knot (knot v0.1.1)

View Source

Fast non-cryptographic PRNG NIF (wyrand).

Drop-in replacement for granderl:uniform/1. Per-OS-thread state via __thread, lazy-seeded from getrandom/arc4random_buf on first use. Biased multiply-and-shift bounded output -- single multiply, no rejection branch (modulo bias under 1e-7 for bounds up to 256, invisible at typical workload scale).

Use knot:uniform/1 to draw a uniformly distributed integer from 1..N. For bounds > 4294967295 (2^32 - 1), the NIF rejects with badarg -- the C-side argument is an unsigned 32-bit int.

Summary

Functions

Return a uniformly distributed integer in 1..N.

Functions

uniform(N)

-spec uniform(1..4294967295) -> 1..4294967295.

Return a uniformly distributed integer in 1..N.

N must be a positive integer that fits in an unsigned 32-bit int (i.e. 1..4294967295). Values outside that range raise badarg.