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

@@ -1004,6 +1004,28 @@
(some (fn (c) (= c 0)) codes)
(some (fn (c) (= c (nth e 1))) codes)))))
(define apl-rng-state 12345)
(define apl-rng-seed! (fn (s) (set! apl-rng-state s)))
(define
apl-rng-next!
(fn
()
(begin
(set!
apl-rng-state
(mod (+ (* apl-rng-state 1103515245) 12345) 2147483648))
apl-rng-state)))
(define
apl-roll
(fn
(arr)
(let
((n (if (scalar? arr) (first (get arr :ravel)) (first (get arr :ravel)))))
(apl-scalar (+ apl-io (mod (apl-rng-next!) n))))))
(define
apl-cartesian
(fn