Anonymous user
Pseudo-random numbers/Xorshift star: Difference between revisions
Pseudo-random numbers/Xorshift star (view source)
Revision as of 16:39, 16 August 2020
, 3 years ago→{{header|REXX}}: changed output alignment, added/changed comments and whitespace, optimized the NEXT function.
(→{{header|REXX}}: added the computer programming language REXX.) |
m (→{{header|REXX}}: changed output alignment, added/changed comments and whitespace, optimized the NEXT function.) |
||
Line 488:
if seed2=='' | seed2=="," then seed2= 987654321 /* " " " " " " */
const= x2d(2545f4914f6cdd1d) /*initialize the constant to be used. */
o.12= copies(0, 12) /*construct 12 bits of zeros. */
o.25= copies(0, 25) /* " 25 " " " */
o.27= copies(0, 27) /* " 27 " " " */
w= max(3, length(n) ) /*for aligning the left side of output.*/
state= seed1 /* " the state to seed #1. */
do j=1 for n
if j==1 then do; say center('n', w) "
say copies('═', w)
end
say right(j':', w)" " right(commas(next()),
end /*j*/
say
Line 512 ⟶ 515:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
b2d: parse arg ?; return x2d( b2x(?
d2b: parse arg ?; return right( x2b( d2x(?
commas: parse arg _; do ?=length(_)-3 to 1 by -3; _= insert(',', _, ?); end; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
next: procedure expose state const o.;
x = xor(x, left(
x = xor(x, right( x ||
x = xor(x, left(
state= b2d(x) /*set STATE to the latest X.*/
return b2d( left( d2b(state * const), 32) ) /*return a
/*──────────────────────────────────────────────────────────────────────────────────────*/
xor: parse arg a, b;
do !=1 for length(a); $= $ || (substr(a,!,1) && substr(b,!,1) )
end /*!*/; return $</lang>
{{out|output|text= when using the default inputs:}}
<pre>
n pseudo─random number
═══ ══════════════════════════
1: 3,540,625,527
2: 2,750,739,987
3: 4,037,983,143
4: 1,993,361,440
5: 3,809,424,708
# count of pseudo─random #
|