def lemire_small

bend-collections-laws-math@1.0.0.0 · src/math/random/rand.bend:145

import bend-collections-laws-math@1.0.0.0/src/math/random/rand.bend as Rand
import Base
import bend-collections-laws-math@1.0.0.0/src/math/u64.bend as W

145# lo >= n >= t accepts at once; otherwise t = 2^64 mod n is computed and at
146# most 127 more draws are made
147def lemire_small(~S: Data, ~next: S -> W.U64 & S, +n: W.U64, +hi: W.U64, +lo: W.U64, s: S, small: Bool) -> W.U64 & S:
148  match small:
149    case False{}:
150      (hi, s)
151    case True{}:
152      result(S, retry(~S, ~next, 127n, n, thresh(n), D{hi, lo, s}))

Uses (8)

Used by (3)