AppleSoft BASIC: Random Number Generators

Applesoft BASIC includes a pseudo-random number generator, function call RND(x).
If x = 0, then the previous random number is returned.

If x > 0, then a new sequence of random numbers is generated by taking the previous random number, multiplying by a constant, and then adding the result to another constant. (The multiplication constant is -3490938.41 and the addition constant is -9.47445545 E-9.) Then the high and low bytes of the resulting 5-byte floating-point number are swapped, the exponent is rotated into the mantissa for further "randomness," and the new exponent is set to -1, insuring a number between 0 and 1. The high and low bytes are swapped to insure a random distribution of numbers greater than and less than 0.5.

If x ;@, then a new sequence is NOT generated, so the multiplication and addition by constants does NOT take place -- only the swapping process, and so on, that follows.

Operating systems have random number algorithms of their own. For details, see the operating system's documentation.
Published Date: Feb 18, 2012