function/RND function/RND
NAME
RND -- Generates a random number
ABBREVIATION
r <shift> N
SYNOPSIS
RND(<seed>)
FUNCTION
This function returns a random number between 0 and 1. This is useful in
games, to simulate dice rolls and other elements of change, and is also
used in some statistical applications. The first random number should be
generated by the formula RND(-TI), to start things off differently every
time. After this, the number in <seed> should be a 1, or any positive
number. If <seed> is zero, RND is re-seeded from the hardware clock ever
time RND is used. A negative value for <seed> seeds the random number
generator using <seed> and gives a random number sequence. The use of
the same negative number for <seed> as a seed results in the same
sequence of random numbers. A positive value gives random numbers based
on the previous seed.
INPUTS
<seed> - a seed, or what the random number is based on
RESULT
A random number between 0 and 1 (numeric).
EXAMPLES
100 X=INT(RND(1)*6)+INT(RND(1)*6)+2
Simulates two dice.
100 X=INT(RND(1)*1000)+1
Number from 1-1000.
100 X=INT(RND(1)*150)+100
Number from 100 to 249.
NOTES
To simulate the rolling of a die, use the formula INT(RND(1)*6+1). First
the random number from 0-1 is multiplied by 6, which expands the range
to 0-6 (actually, greater than zero and less than six). Then 1 is added,
making the range 1 to under 7. The INT function chops off all the
decimal places, leaving the result as a digit from 1 to 6.
To simulate 2 dice, add two of the numbers obtained by the above formula
together.
BUGS
None
SEE ALSO
None