Skip to content

Commit 185f453

Browse files
committed
FEAT: allow seeding random number generation using pairs and tuples
1 parent 9f9ab3e commit 185f453

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/core/t-pair.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@
282282
goto setPair;
283283

284284
case A_RANDOM:
285-
if (D_REF(2)) Trap0(RE_BAD_REFINES); // seed
285+
if (D_REF(2)) { // seed
286+
Set_Random(VAL_INT64(val));
287+
return R_UNSET;
288+
}
286289
x1 = (REBD32)Random_Range((REBINT)x1, (REBOOL)D_REF(3));
287290
y1 = (REBD32)Random_Range((REBINT)y1, (REBOOL)D_REF(3));
288291
goto setPair;

src/core/t-tuple.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@
274274
goto ret_value;
275275
}
276276
if (action == A_RANDOM) {
277-
if (D_REF(2)) Trap0(RE_BAD_REFINES); // seed
277+
if (D_REF(2)) { // seed
278+
Set_Random(Compute_CRC24(vp, len));
279+
return R_UNSET;
280+
}
278281
for (;len > 0; len--, vp++) {
279282
if (*vp)
280283
*vp = (REBYTE)(Random_Int(D_REF(3)) % (1+*vp));

0 commit comments

Comments
 (0)