Pseudo-random numbers/Xorshift star: Difference between revisions

m
→‎{{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) " " pseudo─random number"
say copies('═', w) " ════════════════════════════════════════════════"
end
say right(j':', w)" " right(commas(next()), 1718) /*display a random number*/
end /*j*/
say
Line 512 ⟶ 515:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
b2d: parse arg ?; return x2d( b2x(?)) ) /*convert bin ──► decimal. */
d2b: parse arg ?; return right( x2b( d2x(?)) + 0), 64, 0) /*convert dec ──► 64 bit bin.*/
commas: parse arg _; do ?=length(_)-3 to 1 by -3; _= insert(',', _, ?); end; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
next: procedure expose state const o.; x= d2b(state) /*convert STATE to binary. */
x = xor(x, left( copies(0, o.12) || x, 64) ) /*shift right 12 bits and XOR*/
x = xor(x, right( x || copies(0, o.25), 64) ) /* " left 25 " " " */
x = xor(x, left( copies(0, o.27) || x, 64) ) /* " right 27 " " " */
state= b2d(x) /*set STATE to the latest X.*/
return b2d( left( d2b(state * const), 32) ) /*return a pseduo─randompseudo─random num.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
xor: parse arg a, b; $= $= /*perform a bit─wise XOR. */
do !=1 for length(a); $= $ || (substr(a,!,1) && substr(b,!,1) )</lang>
end /*!*/; return $</lang>
{{out|output|text=&nbsp; 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 #