The rand() Command


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

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-ShareAlike 3.0 License