Subtractive generator: Difference between revisions
→{{header|jq}}: state: []
(→{{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>#
# which sets .x as the PRN and which expects the the input to
# be the PRNG state, which is updated.
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}
| .state[0] = ($p % .mod)
| reduce range(1; 55) as $i (.;
if .j >= 55 then .j += -55 else . end
Line 1,111 ⟶ 1,109:
subrandSeed(null);
▲| subrandSeed(292929)
| foreach range(0; 10) as $i (.;
subrand;
|