Subtractive generator: Difference between revisions
Content added Content deleted
m (Formatting.) |
m (→{{header|REXX}}: elided a blank line, aligned some statements, changed some comments.) |
||
Line 1,742: | Line 1,742: | ||
Some optimization was done so that the first two '''do''' loops executed faster. |
Some optimization was done so that the first two '''do''' loops executed faster. |
||
<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 |
|||
numeric digits 20; billion= 10**9 /*same as─►─┘ */ |
|||
cI= 55; |
cI= 55; do i=2 for cI-2; s.i= mod( s(i-2) - s(i-1), billion) |
||
⚫ | |||
s.i= mod( s(i-2) - s(i-1), billion) |
|||
⚫ | |||
Cp= 34 |
Cp= 34 |
||
do j=0 for 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 |
|||
r._= mod( r( mod(k-cI, cI)) - r( mod(k-cJ, cI) ), billion) |
|||
end /*m*/ |
|||
t= 235 |
t= 235 |
||
do n=m+1 to t; _= n // cI |
|||
r._= mod( r( mod(n-cI, cI)) - r( mod(n-cJ, cI) ), billion) |
|||
say right(r._, 40) |
|||
end /*n*/ |
|||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
mod: procedure; |
mod: procedure; parse arg a,b; return ( (a // b) + b) // b |
||
r: |
r: parse arg #; return r.# |
||
s: |
s: parse arg #; return s.#</lang> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |