Syntax:
randomInteger% = rnd(expr%)
Description:
This function returns a pseudo-random long integer uniformly distributed in the range 1 through expr&
. The expr&
parameter should be greater than 1, and must not exceed 65536. If the value returned is to be assigned to a 16-bit integer (randomInteger%
), expr&
should not exceed 32767. The actual sequence of numbers returned by rnd
depends on the random number generator's "seed" value; see the random statement for more information. Note that rnd(1)
always returns the value 1.
Example:
To get a random integer between two arbitrary limits min
and max
, use this statement:
randomInteger = rnd(max - min + 1) + min - 1
(Note: max - min
must be less than or equal to 65536.)
To get a random fraction, greater than or equal to zero and less than 1, use this statement:
frac! = (rnd(65536)-1)/65536.0
To get a random long integer in the range 1 through 2,147,483,647, use this statement:
randomInteger& = ((rnd(65536) - 1)<<15) + rnd(32767)
See Also:
random; maybe