The rand() 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.

rand.png

Command Summary

Generates a random number.

Command Syntax

rand() or rand(n)

Menu Location

  • Press 2nd MATH to enter the MATH popup menu.
  • Press 7 to enter the Probability submenu.
  • Press 4 to paste rand(.

Calculator Compatibility

This command works on all calculators.

Token Size

2 bytes

The rand() command generates a random number. It can be used in one of two ways:

  • rand() gives a random real number between 0 and 1.
  • rand(n) gives a random integer between 1 and n.

By adding or multiplying appropriately, you can change these bounds. For example, 10rand() gives a random real number between 0 and 10, and rand(9)-5 gives a random number between -4 and 4.

L'Ecuyer's algorithm is used by TI calculators to generate pseudorandom numbers.

:RandSeed 0
:rand()
           .943597402492
:rand()
           .908318860975
:rand(10)
           2

Advanced Uses

Using the RandSeed command makes the random numbers entirely predictable: after setting the random seed to some value, the same random numbers will be returned every time.

Error Conditions

260 - Domain error happens when the maximum number is 1014 or greater.

Related Commands

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