/** {@inheritDoc} */ public int nextInt() { return next(32); }
/** {@inheritDoc} */ public boolean nextBoolean() { return next(1) != 0; }
/** {@inheritDoc} */ public float nextFloat() { return next(23) * 0x1.0p-23f; }
/** * Returns a pseudorandom, uniformly distributed {@code long} value * between 0 (inclusive) and the specified value (exclusive), drawn from * this random number generator's sequence. * * @param n the bound on the random number to be returned. Must be * positive. * @return a pseudorandom, uniformly distributed {@code long} * value between 0 (inclusive) and n (exclusive). * @throws IllegalArgumentException if n is not positive. */ public long nextLong(long n) throws IllegalArgumentException { if (n > 0) { long bits; long val; do { bits = ((long) next(31)) << 32; bits |= ((long) next(32)) & 0xffffffffL; val = bits % n; } while (bits - val + (n - 1) < 0); return val; } throw new NotStrictlyPositiveException(n); }
/** * {@inheritDoc} * <p>This default implementation is copied from Apache Harmony * java.util.Random (r929253).</p> * * <p>Implementation notes: <ul> * <li>If n is a power of 2, this method returns * {@code (int) ((n * (long) next(31)) >> 31)}.</li> * * <li>If n is not a power of 2, what is returned is {@code next(31) % n} * with {@code next(31)} values rejected (i.e. regenerated) until a * value that is larger than the remainder of {@code Integer.MAX_VALUE / n} * is generated. Rejection of this initial segment is necessary to ensure * a uniform distribution.</li></ul></p> */ public int nextInt(int n) throws IllegalArgumentException { if (n > 0) { if ((n & -n) == n) { return (int) ((n * (long) next(31)) >> 31); } int bits; int val; do { bits = next(31); val = bits % n; } while (bits - val + (n - 1) < 0); return val; } throw new NotStrictlyPositiveException(n); }
/** {@inheritDoc} */ public float nextFloat() { return next(23) * 0x1.0p-23f; }
/** {@inheritDoc} */ public boolean nextBoolean() { return next(1) != 0; }
/** {@inheritDoc} */ public boolean nextBoolean() { return next(1) != 0; }
/** {@inheritDoc} */ public int nextInt() { return next(32); }
/** {@inheritDoc} */ public float nextFloat() { return next(23) * 0x1.0p-23f; }
/** {@inheritDoc} */ public int nextInt() { return next(32); }
/** * Returns a pseudorandom, uniformly distributed {@code long} value * between 0 (inclusive) and the specified value (exclusive), drawn from * this random number generator's sequence. * * @param n the bound on the random number to be returned. Must be * positive. * @return a pseudorandom, uniformly distributed {@code long} * value between 0 (inclusive) and n (exclusive). * @throws IllegalArgumentException if n is not positive. */ public long nextLong(long n) throws IllegalArgumentException { if (n > 0) { long bits; long val; do { bits = ((long) next(31)) << 32; bits |= ((long) next(32)) & 0xffffffffL; val = bits % n; } while (bits - val + (n - 1) < 0); return val; } throw new NotStrictlyPositiveException(n); }
/** * Returns a pseudorandom, uniformly distributed {@code long} value * between 0 (inclusive) and the specified value (exclusive), drawn from * this random number generator's sequence. * * @param n the bound on the random number to be returned. Must be * positive. * @return a pseudorandom, uniformly distributed {@code long} * value between 0 (inclusive) and n (exclusive). * @throws IllegalArgumentException if n is not positive. */ public long nextLong(long n) throws IllegalArgumentException { if (n > 0) { long bits; long val; do { bits = ((long) next(31)) << 32; bits |= ((long) next(32)) & 0xffffffffL; val = bits % n; } while (bits - val + (n - 1) < 0); return val; } throw new NotStrictlyPositiveException(n); }