Subtractive generator: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: used a template for the output section.) |
m (→{{header|REXX}}: added whitespace.) |
||
Line 1,536: | Line 1,536: | ||
{{trans|PL/I}} |
{{trans|PL/I}} |
||
<lang rexx>/*REXX program uses a subtractive generator, and creates a sequence of random numbers. */ |
<lang rexx>/*REXX program uses a subtractive generator, and creates a sequence of random numbers. */ |
||
s.0=292929; |
s.0= 292929; s.1= 1; billion= 1e9 /* ◄────────┐ */ |
||
numeric digits 20; billion=10**9 |
numeric digits 20; billion= 10**9 /*same as─►─┘ */ |
||
cI=55; |
cI= 55; do i=2 to cI-1 |
||
s.i=mod(s(i-2) - s(i-1), billion) |
s.i= mod( s(i-2) - s(i-1), billion) |
||
end /*i*/ |
end /*i*/ |
||
Cp=34 |
Cp= 34 |
||
do j=0 to cI-1 |
do j=0 to cI-1 |
||
r.j=s(mod(cP*(j+1), cI)) |
r.j= s( mod( cP * (j+1), cI)) |
||
end /*j*/ |
end /*j*/ |
||
m=219; Cj=24 |
m= 219; Cj= 24 |
||
do k=cI to m; _=k//cI |
do k=cI to m; _= k // cI |
||
r._=mod(r(mod(k-cI, cI)) - r(mod(k-cJ, cI)), billion) |
r._= mod( r( mod(k-cI, cI)) - r( mod(k-cJ, cI)), billion) |
||
end /*m*/ |
end /*m*/ |
||
t=235 |
t= 235 |
||
do n=m+1 to t; _=n//cI |
do n=m+1 to t; _= n // cI |
||
r._=mod(r(mod(n-cI, cI)) - r(mod(n-cJ, cI)), billion) |
r._= mod( r( mod(n-cI, cI)) - r( mod(n-cJ, cI)), billion) |
||
say right(r._, 40) |
say right(r._, 40) |
||
end /*n*/ |
end /*n*/ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
mod: procedure; parse arg a,b; return ((a // b) + b) // b |
mod: procedure; parse arg a,b; return ( (a // b) + b) // b |
||
r: parse arg #; return r.# |
r: parse arg #; return r.# |
||
s: parse arg #; return s.#</lang> |
s: parse arg #; return s.#</lang> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |