def uniform

mlbend-generative@0.1.1.0 · main.bend:64

import mlbend-generative@0.1.1.0/main.bend as MlbendGenerative
import Base

64# a uniform in (0, 1]: the low 24 bits of the hash plus one, exactly
65# representable, so log(u) is never log(0)
66def uniform(+s: Nat, +i: Nat) -> F32:
67  h = mix32(hash_of(s, i))
68  m = ((U32.and(h, U32.from_nat(16777215n)) + 1 : U32) : U32)
69  (F32.from_nat(U32.to_nat(m)) / 16777216.0 : F32)

Uses (11)

Used by (1)