Linear congruential generator: Difference between revisions

Corrected an error in implementation of Microsoft LCG. Added code to compute ten first values. Added output.
(Added Wren)
(Corrected an error in implementation of Microsoft LCG. Added code to compute ten first values. Added output.)
Line 2,190:
=={{header|Nim}}==
<lang nim>proc bsdRand(seed: int): iterator: int =
var seedstate = seed
result = iterator: int =
while true:
seedstate = (11035152451_103_515_245 * seedstate + 1234512_345) and 0x7fffffff
yield seedstate
 
proc msvcrtRand(seed: int): iterator: int =
var seedstate = seed
result = iterator: int =
while true:
seedstate = (214013214_013 * seedstate + 25310112_531_011) and 0x7fffffff
yield seed</lang>state shr 16
 
echo "BSD with seed = 1 (OEIS A096553):"
var count = 0
let iter1 = bsdRand(1)
for val in iter1():
echo val
inc count
if count == 10:
break
 
echo ""
echo "Microsoft with seed = 0 (OEIS A096558):"
count = 0
let iter2 = msvcrtRand(0)
for val in iter2():
echo val
inc count
if count == 10:
break</lang>
 
{{out}}
<pre>BSD with seed = 1 (OEIS A096553):
1103527590
377401575
662824084
1147902781
2035015474
368800899
1508029952
486256185
1062517886
267834847
 
Microsoft with seed = 0 (OEIS A096558):
38
7719
21238
2437
8855
11797
8365
32285
10450
30612</pre>
 
=={{header|Oforth}}==
Anonymous user