Subtractive generator: Difference between revisions
Content added Content deleted
(→{{header|jq}}: state: []) |
|||
Line 1,077: | Line 1,077: | ||
except insofar as a subfunction may call its parent (or grandparent, etc), |
except insofar as a subfunction may call its parent (or grandparent, etc), |
||
we have defined `subrand` as an accessible subfunction of `subrandSeed`. |
we have defined `subrand` as an accessible subfunction of `subrandSeed`. |
||
<lang jq># |
<lang jq># If $p is null, then call `subrand`, |
||
# which sets .x as the PRN and which expects the the input to |
|||
# output: updated state |
|||
# be the PRNG state, which is updated. |
|||
# If $p is null, then just call `subrand`, which sets .x as the PRN. |
|||
def subrandSeed($p): |
def subrandSeed($p): |
||
Line 1,092: | Line 1,092: | ||
if $p == null then subrand |
if $p == null then subrand |
||
else |
else |
||
{mod: 1e9, state: [], si: 0, sj: 0, p: $p, p2: 1, j: 21} |
|||
.p = $p |
|||
| .p2 = 1 |
|||
| .state[0] = ($p % .mod) |
| .state[0] = ($p % .mod) |
||
| .j = 21 |
|||
| reduce range(1; 55) as $i (.; |
| reduce range(1; 55) as $i (.; |
||
if .j >= 55 then .j += -55 else . end |
if .j >= 55 then .j += -55 else . end |
||
Line 1,111: | Line 1,109: | ||
subrandSeed(null); |
subrandSeed(null); |
||
⚫ | |||
{ mod: 1e9, |
|||
state: [range(0;55)|0], |
|||
si: 0, |
|||
sj: 0 } |
|||
⚫ | |||
| foreach range(0; 10) as $i (.; |
| foreach range(0; 10) as $i (.; |
||
subrand; |
subrand; |