Random.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. If 0, returns 0.

Returns

A random integer in [0, bound).