Skip to content

RND

Random

This numeric function generates a pseudo-random number in the range of 0 < n < 1.

RND (numeric-value [,ERR=line-ref|,ERC=error-code])
numeric-value
is any number.
line-ref
is the program line number or label to branch to if an error is produced by this function.
error-code
is a programmer-defined error code. Valid values are positive or negative whole numbers.

This function returns a pseudo-random decimal value between 0 and 1.

This function generates different random number sequences according to the following numeric values:

  • A positive numeric-value returns the next random number in the series.
  • A zero numeric-value returns the last value generated.
  • A negative numeric-value provides a ‘seed’ to start a new sequence of random numbers. The same negative number always yields the same series.

The pseudo-random sequence repeats every 2,796,203 numbers.

The pseudo-random sequence starts at the same value every time Thoroughbred Basic is run. This allows the user to readily construct programs, which repeat the same sequences.

If, however, it is desired to avoid repeating the same sequence, some additional randomization can be provided by generating the first random number in a program with RND(-TIM).

PRINT RND (-1)

The number generated in this particular series is 0.13486288370342.

PRINT RND (0)

repeats the above number, 0.13486288370342.

The above examples assume PRECISION 14.

From the Thoroughbred Basic Language Reference, Volume III: R–Z, version 8.9.1. Open this page in the PDF