def buffered_bounded_lemire_uint32(bitgen, rng):
    """
    Generates a random unsigned 32 bit integer bounded
    within a given interval using Lemire's rejection.
    """
    rng_excl = np.uint32(rng) + np.uint32(1)

    assert (rng != 0xFFFFFFFF)

    # Generate a scaled random number.
    m = np.uint64(next_uint32(bitgen)) * np.uint64(rng_excl)

    # Rejection sampling to remove any bias
    leftover = m & 0xFFFFFFFF

    if (leftover < rng_excl):
        # `rng_excl` is a simple upper bound for `threshold`.
        threshold = (UINT32_MAX - rng) % rng_excl

        while (leftover < threshold):
            m = np.uint64(next_uint32(bitgen)) * np.uint64(rng_excl)
            leftover = m & 0xFFFFFFFF

    return (m >> 32)

    Generates a random unsigned 32 bit integer bounded
    within a given interval using Lemire's rejection.
    
numba/np/random/new_random_methods.py