Linear congruential generator: Difference between revisions

Content added Content deleted
No edit summary
m (→‎{{header|REXX}}: used variables to hold a couple of powers of 2, added/changed comments and whitespace, used whitespace in the two centered output titles.)
Line 2,689: Line 2,689:
/*──────────── number generators. BSD= 0 ──► (2**31)-1 MS= 0 ──► (2**16)-1 */
/*──────────── number generators. BSD= 0 ──► (2**31)-1 MS= 0 ──► (2**16)-1 */
numeric digits 20 /*use enough dec. digs for the multiply*/
numeric digits 20 /*use enough dec. digs for the multiply*/
two@@16= 2**16 /*use a variable to contain 2^16 */
two@@31= 2**31 /* " " " " " 2^32 */


do seed=0 to 1 /*perform for seed=0 and also seed=1.*/
do seed=0 for 2; bsd= seed /*perform for seed=0 and also seed=1.*/
bsd= seed; ms= seed /*assign SEED to two REXX variables.*/
ms= seed /*assign SEED to two REXX variables.*/
say center('seed='seed, 79, "") /*display the seed in a title/separator*/
say center(' seed='seed" ", 79, '') /*display the seed in a title/separator*/
/* [↓] show 20 rand #'s for each seed.*/
/* [↓] show 20 rand #'s for each seed.*/
do j=1 for 20 /*generate and display 20 rand numbers.*/
do j=1 for 20 /*generate and display 20 rand numbers.*/
bsd = (1103515245 * bsd + 12345) // 2**31
bsd = (1103515245 * bsd + 12345) // two@@31
ms = ( 214013 * ms + 2531011) // 2**31
ms = ( 214013 * ms + 2531011) // two@@31
say ' state' right(j,3) " BSD" right(bsd, 11) left('', 13),
say ' state' right(j,3) " BSD" right(bsd, 11) left('', 13),
" MS" right( ms, 11) left('', 5),
" MS" right( ms, 11) left('', 5),
" rand" right(ms%2**16, 6)
" rand" right(ms % two@@16, 6)
end /*j*/
end /*j*/
end /*seed*/ /*stick a fork in it, we're all done. */</lang>
end /*seed*/ /*stick a fork in it, we're all done. */</lang>
{{out|output|text= &nbsp; &nbsp; (shown at five-sixth size.) }}
{{out|output|text= &nbsp; &nbsp; (shown at five-sixth size.) }}
<pre style="font-size:84%">
<pre style="font-size:84%">
─────────────────────────────────── seed=0 ────────────────────────────────────
────────────────────────────────────seed=0─────────────────────────────────────
state 1 BSD 12345 MS 2531011 rand 38
state 1 BSD 12345 MS 2531011 rand 38
state 2 BSD 1406932606 MS 505908858 rand 7719
state 2 BSD 1406932606 MS 505908858 rand 7719
Line 2,725: Line 2,727:
state 19 BSD 996984527 MS 196417061 rand 2997
state 19 BSD 996984527 MS 196417061 rand 2997
state 20 BSD 1157490780 MS 962080852 rand 14680
state 20 BSD 1157490780 MS 962080852 rand 14680
─────────────────────────────────── seed=1 ────────────────────────────────────
────────────────────────────────────seed=1─────────────────────────────────────
state 1 BSD 1103527590 MS 2745024 rand 41
state 1 BSD 1103527590 MS 2745024 rand 41
state 2 BSD 377401575 MS 1210316419 rand 18467
state 2 BSD 377401575 MS 1210316419 rand 18467