Powerball Number Generator
Powerball Random Number Generator using the Forth Programming Language
Source code
DECIMAL
VARIABLE RND ( seed )
: RANDOM ( – n, a random number within 0 to 65536 )
RND @ 31421 * ( RND*31421 )
6927 + ( RND*31421+6926, mod 65536)
DUP RND ! ( refresh he seed )
;
: CHOOSE ( n1 – n2, a random number within 0 to n1 )
RANDOM UM* ( n1*random to a double product)
SWAP DROP ( discard lower part )
; ( in fact divide by 65536 )
HERE RND !
\ To test the routine, type
\ 100 CHOOSE .
\ 100 CHOOSE .
\ 100 CHOOSE .
\ and varify that the results are randomly distributed betweem 0 and
\ 99 .
HERE RND ! ( initialize seed )
\ From
\ https://wiki.forth-ev.de/lib/exe/fetch.php/projects:430eforth:eforth_lessons.pdf
\ powerball megamillions random num gen
: pwrball 5 0 do 65 choose . loop 25 choose ." Powerball: " . ;
: luckynums begin pwrball cr key? until ;