TI-BASIC:Randint

From Learn @ Cemetech
Revision as of 18:34, 24 February 2016 by Maintenance script (talk | contribs) (Initial automated import)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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