Subtractive generator: Difference between revisions

(→‎{{header|jq}}: state: [])
Line 1,077:
except insofar as a subfunction may call its parent (or grandparent, etc),
we have defined `subrand` as an accessible subfunction of `subrandSeed`.
<lang jq># input:If $p is null, then call `subrand`, state
# 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):
 
Line 1,092:
if $p == null then subrand
else
{mod: 1e9, state: [], si: 0, sj: 0, p: $p, p2: 1, j: 21}
.p = $p
| .p2 = 1
| .state[0] = ($p % .mod)
| .j = 21
| reduce range(1; 55) as $i (.;
if .j >= 55 then .j += -55 else . end
Line 1,111 ⟶ 1,109:
subrandSeed(null);
 
| subrandSeed(292929)
{ mod: 1e9,
state: [range(0;55)|0],
si: 0,
sj: 0 }
| subrandSeed(292929)
| foreach range(0; 10) as $i (.;
subrand;
2,468

edits