private static long nextLong(long n) {
        // Extracted from o.a.c.rng.core.BaseProvider.nextLong(long)
        long bits;
        long val;
        do {
            bits = RANDOM.nextLong() >>> 1;
            val = bits % n;
        } while (bits - val + (n - 1) < 0);

        return val;
    }
Generates a {@code long} value between 0 (inclusive) and the specified
value (exclusive).

@param n Bound on the random number to be returned.  Must be positive.
@return a random {@code long} value between 0 (inclusive) and {@code n}
(exclusive).
android/android_framework/base/src/main/java/lang3/RandomUtils.java