def below.go

bend-kit-random@0.1.0.1 · random.bend:54

import bend-kit-random@0.1.0.1/random.bend as Random
import Base

54# Rejects draws below t = 2^32 mod n, as OpenBSD's arc4random_uniform does.
55def below.go(fuel: Nat, +n: U32, +t: U32, xr: U32 & Rng) -> U32 & Rng:
56  match fuel:
57    case 0n:
58      (x, r) = xr
59      ((x % n : U32), r)
60    case 1n+p:
61      (+x, +r) = xr
62      Bool.case(U32 & Rng, U32.is_ge(x, t),
63        u => ((x % n : U32), r),
64        u => below.go(p, n, t, next(r)))

Uses (9)

Used by (1)