BASIC stamp manual v2.2

RANDOM – BASIC Stamp Command Reference
Page 360 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
SYMBOL result = W1
Setup:
result = 11000
Main:
RANDOM result
DEBUG result
GOTO Main
-- or --
result VAR Word
Setup:
result = 11000
Main:
RANDOM result
DEBUG DEC ? result
GOTO Main
Here, result is only initialized once, before the loop. Each time through the
loop, the previous value of result, generated by RANDOM, is used as the
next seed value. This generates a more desirable set of pseudorandom
numbers.
In applications requiring more apparent randomness, it's necessary to
"seed" RANDOM with a more random value every time. For instance, in
the demo program below, RANDOM is executed continuously (using the
previous resulting number as the next seed value) while the program
waits for the user to press a button. Since the user can’t control the timing
of button presses very accurately, the results approach true randomness.
Figure 5.32: RANDOM Button
Circuit.
1
All
2