@lelantos-org/sdk / core / randomBelow
Function: randomBelow() โ
ts
function randomBelow(n, bytes?): number;Defined in: @lelantos-org/sdk/dist/core/random.d.ts:36
Uniform integer in [0, n).
Rejection-sampled rather than Math.floor(randomFloat01() * n): scaling a float spreads 2^56 outcomes over n buckets, which are equal in size only when n is a power of two. The bias is tiny at small n but it is a bias in a slot permutation, which is exactly the thing the permutation exists to remove.
bytes is injectable so a test can force a permutation; it must behave like randomBytes.
Parameters โ
| Parameter | Type |
|---|---|
n | number |
bytes? | (k) => Uint8Array |
Returns โ
number