Jump to content

Linear congruential generator: Difference between revisions

Added PicoLisp
(Added PicoLisp)
Line 70:
BSD()=BSDseed=1103515245*BSDseed+12345;lift(BSDseed);
MSFT()=MSFTseed=214013*MSFTseed+2531011;lift(MSFTseed)%(1<<31);</lang>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(zero *BsdSeed *MsSeed)
 
(de bsdRand ()
(setq *BsdSeed
(& (+ 12345 (* 1103515245 *BsdSeed)) `(dec (** 2 31))) ) )
 
(de msRand ()
(>> 16
(setq *MsSeed
(& (+ 2531011 (* 214013 *MsSeed)) `(dec (** 2 31))) ) ) )</lang>
Output:
<pre>: (do 7 (printsp (bsdRand)))
12345 1406932606 654583775 1449466924 229283573 1109335178 1051550459 -> 1051550459
 
: (do 12 (printsp (msRand)))
38 7719 21238 2437 8855 11797 8365 32285 10450 30612 5853 28100 -> 28100</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.