Skip to content

Commit

Permalink
FEAT: allow seeding random number generation using pairs and tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Mar 25, 2024
1 parent 9f9ab3e commit 185f453
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/t-pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@
goto setPair;

case A_RANDOM:
if (D_REF(2)) Trap0(RE_BAD_REFINES); // seed
if (D_REF(2)) { // seed
Set_Random(VAL_INT64(val));
return R_UNSET;
}
x1 = (REBD32)Random_Range((REBINT)x1, (REBOOL)D_REF(3));
y1 = (REBD32)Random_Range((REBINT)y1, (REBOOL)D_REF(3));
goto setPair;
Expand Down
5 changes: 4 additions & 1 deletion src/core/t-tuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@
goto ret_value;
}
if (action == A_RANDOM) {
if (D_REF(2)) Trap0(RE_BAD_REFINES); // seed
if (D_REF(2)) { // seed
Set_Random(Compute_CRC24(vp, len));
return R_UNSET;
}
for (;len > 0; len--, vp++) {
if (*vp)
*vp = (REBYTE)(Random_Int(D_REF(3)) % (1+*vp));
Expand Down

0 comments on commit 185f453

Please sign in to comment.