/** * Reseeds the secure random number generator with the supplied seed. * <p> * Will create and initialize if null. * </p> * * @param seed the seed value to use */ public void reSeedSecure(long seed) { getSecRan().setSeed(seed); }
/** * Reseeds the secure random number generator with the current time in * milliseconds. * <p> * Will create and initialize if null. * </p> */ public void reSeedSecure() { getSecRan().setSeed(System.currentTimeMillis()); }
/** {@inheritDoc} */ public int nextSecureInt(final int lower, final int upper) throws NumberIsTooLargeException { return new UniformIntegerDistribution(getSecRan(), lower, upper).sample(); }
final RandomGenerator secRan = getSecRan(); MessageDigest alg = null; try {
/** {@inheritDoc} */ public long nextSecureLong(final long lower, final long upper) throws NumberIsTooLargeException { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, false); } final RandomGenerator rng = getSecRan(); final long max = (upper - lower) + 1; if (max <= 0) { // the range is too wide to fit in a positive long (larger than 2^63); as it covers // more than half the long range, we use directly a simple rejection method while (true) { final long r = rng.nextLong(); if (r >= lower && r <= upper) { return r; } } } else if (max < Integer.MAX_VALUE){ // we can shift the range and generate directly a positive int return lower + rng.nextInt((int) max); } else { // we can shift the range and generate directly a positive long return lower + nextLong(rng, max); } }
/** * Reseeds the secure random number generator with the current time in * milliseconds. * <p> * Will create and initialize if null. * </p> */ public void reSeedSecure() { getSecRan().setSeed(System.currentTimeMillis()); }
/** * Reseeds the secure random number generator with the supplied seed. * <p> * Will create and initialize if null. * </p> * * @param seed the seed value to use */ public void reSeedSecure(long seed) { getSecRan().setSeed(seed); }
/** {@inheritDoc} */ public int nextSecureInt(final int lower, final int upper) throws NumberIsTooLargeException { return new UniformIntegerDistribution(getSecRan(), lower, upper).sample(); }
final RandomGenerator secRan = getSecRan(); MessageDigest alg = null; try {
/** {@inheritDoc} */ public long nextSecureLong(final long lower, final long upper) throws NumberIsTooLargeException { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, false); } final RandomGenerator rng = getSecRan(); final long max = (upper - lower) + 1; if (max <= 0) { // the range is too wide to fit in a positive long (larger than 2^63); as it covers // more than half the long range, we use directly a simple rejection method while (true) { final long r = rng.nextLong(); if (r >= lower && r <= upper) { return r; } } } else if (max < Integer.MAX_VALUE){ // we can shift the range and generate directly a positive int return lower + rng.nextInt((int) max); } else { // we can shift the range and generate directly a positive long return lower + nextLong(rng, max); } }