The randInt( Command

We're glad you came by, but you might find what you're looking for elsewhere.

TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it.

Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope.

RANDINT.GIF

Command Summary

Generates a random integer between min and max, inclusive, or a list of such numbers.

Command Syntax

randInt(min,max[,# of numbers])

Menu Location

Press:

  1. MATH to access the math menu.
  2. LEFT to access the PRB submenu.
  3. 5 to select randInt(, or use arrows.

Calculator Compatibility

TI-83/84/+/SE

Token Size

2 bytes

randInt(min,max) generates a uniformly-distributed pseudorandom integer between min and max inclusive. randInt(min,max,n) generates a list of n uniformly-distributed pseudorandom integers between min and max.

seed→rand affects the output of randInt(.

0→rand
     0
randInt(1,10)
     10
randInt(1,10,5)
     {10 2 6 5 8}

Optimization

When the lower bound of randInt( is 0, you can replace it with int(#rand to save space. For example:

:randInt(0,12
can be
:int(13rand

Similarly, if you don't want to include zero in the range, you can use a variant of 1-#int(#rand:

:1-2int(2rand

In this particular example, the only values that you will ever get are -1 or 1.

Formulas

The value of randInt( for a given seed can be expressed in terms of rand:

randInt(A,B)=

  • when A<B, A+int((B-A+1)rand
  • otherwise, B+int((A-B+1)rand

This is identical to the output of randInt( in the sense that for the same seed, both expressions will generate the same random numbers.

Error Conditions

  • ERR:DOMAIN is thrown if any of the arguments is a decimal.
  • ERR: DATA TYPE is given if you use imaginary numbers like 6i or something like Matrices or Lists. This error is used instead of ERR:DOMAIN for "i".

Related Commands

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.