def random_bounded_uint16_fill(bitgen, low, rng, size, dtype):
    """
    Returns a new array of given size with 16 bit integers
    bounded by given interval.
    """
    buf = 0
    bcnt = 0

    out = np.empty(size, dtype=dtype)
    if rng == 0:
        for i in np.ndindex(size):
            out[i] = low
    elif rng == 0xFFFF:
        # Lemire16 doesn't support rng = 0xFFFF.
        for i in np.ndindex(size):
            val, bcnt, buf = buffered_uint16(bitgen, bcnt, buf)
            out[i] = low + val

    else:
        for i in np.ndindex(size):
            val, bcnt, buf = \
                buffered_bounded_lemire_uint16(bitgen, rng,
                                               bcnt, buf)
            out[i] = low + val
    return out

    Returns a new array of given size with 16 bit integers
    bounded by given interval.
    
numba/np/random/old_random_methods.py