apl: ? roll/random + apl-rng-seed! (+4 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 55s

apl-rng-state global mutable LCG.
apl-rng-seed! for deterministic tests.
apl-rng-next! advances state.
apl-roll: monadic ?N returns scalar in 1..N (apl-io-relative).

apl-monadic-fn dispatches "?" → apl-roll.

apl-run "?10" → 8 (with seed 42)
apl-run "?100" → in 1..100
This commit is contained in:
2026-05-07 22:19:57 +00:00
parent 0b3610a63a
commit bcdd137d6f
4 changed files with 46 additions and 1 deletions

View File

@@ -359,3 +359,24 @@
"inline-assign in dfn: f ← {x + x ← ⍵} ⋄ f 8 → 16"
(mkrv (apl-run "f ← {x + x ← ⍵} ⋄ f 8"))
(list 16))
(begin (apl-rng-seed! 42) nil)
(apl-test
"?10 with seed 42 → 8 (deterministic)"
(mkrv (apl-run "?10"))
(list 8))
(apl-test "?10 next call → 5" (mkrv (apl-run "?10")) (list 5))
(apl-test
"?100 stays in range"
(let ((v (first (mkrv (apl-run "?100"))))) (and (>= v 1) (<= v 100)))
true)
(begin (apl-rng-seed! 42) nil)
(apl-test
"?10 with re-seed 42 → 8 (reproducible)"
(mkrv (apl-run "?10"))
(list 8))