CryptoRandom.nextUintBound

uint nextUintBound(uint bound)

Generates a random unsigned integer in the half-open interval [0, bound).

Uses rejection sampling to avoid modulo bias, ensuring a uniform distribution even when bound is not a power of two.

Parameters

boundThe exclusive upper bound; must not be 0 because the empty interval [0, 0) contains no value.

Returns

A random integer in [0, bound).

Throws

CryptoException if bound is 0.