flan/test/programs/sand-headless.flan
Joseph Ferano a0278378ab Five randomness functions, and a draw wide enough to answer them
rand-int, rand, rand-bool, rand-int-range and rand-float-range, at the widths
the author ruled: a u64 draw and an f64 in [0, 1). rand-seed and rand-state
keep their names. The four old names are not names, and each is refused by the
one that is, with a call that compiles — in both the call and the bare-name
position, because a Lisp-1 makes the second a real thing to write.

The generator's step is untouched, so a seed means what it meant. Its output
function is not: PCG-XSH-RR folded the state to 32 bits, and no honest u64 or
53-bit f64 comes out of 32 bits without a second step. PCG-RXS-M-XS 64 answers
64 from the same one, so all five still cost exactly one draw and a seeded run
is reproducible. The price, written where it lives: the permutation is a
bijection of the state, which is what 64 output bits from 64 state bits costs.

The sequence is therefore a different one, and programs/rand.flan pins it —
reproducibility across the five, the single-draw cost of each, the half-open
boundaries, and rand-bool's count over a thousand flips.

sand.flan is not touched. It calls rand-f32, so the cases that compile or
re-evaluate it skip themselves on the fixture rather than on a comment: fix
its two calls and every one of them runs again. Its hash is the old
generator's grid and gets re-taken then.
2026-09-21 10:57:18 +07:00

34 lines
1.3 KiB
Plaintext

;;;; sand.flan's other half: N frames, no window, hash the grid.
;;;;
;;;; This is the version CI runs on native *and* wasm32, and it imports
;;;; sand.flan itself — window, raylib bindings, dev agent and all. It builds
;;;; for wasm32 anyway because the link follows what the program reaches:
;;;; nothing here calls into raylib, so no shim is compiled and no -lraylib is
;;;; passed, and the front-end's own functions are never emitted. sand.flan's
;;;; main is not exported, so the only main is this one.
;;;;
;;;; A package is a directory, except when it is a single .flan file named
;;;; outright — which is this, because sand.flan shares the repository root
;;;; with three other loose programs.
;;;;
;;;; The hash is a regression test only because the sequence is reproducible:
;;;; rand is a seeded PRNG written in Flan, so the same seed gives the same
;;;; grains in the same places on both targets (plan.org, RNG is ours).
(import sand "../../sand.flan")
(defconst frames 40)
(defn main [] i32
(rand-seed 20260910)
;; Four clouds, spread across the top, one per colour. Deterministic
;; positions: the mouse is what the interactive driver has and this does not.
(dotimes [i 4]
(sand/next-color)
(sand/paint-at 4 (* (+ i 1) (/ sand/cols 5))))
(dotimes [f frames]
(sand/step))
(print (sand/hash-grid))
(println "")
0)