public final class RandomUtils extends Object
The source of random stuff for the whole project. This lets us make all randomness in the project predictable, if desired, for when we run unit tests, which should be repeatable.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_INT_SMALLER_TWIN_PRIME
The largest prime less than 231-1 that is the smaller of a twin prime pair.
|
Modifier and Type | Method and Description |
---|---|
static RandomWrapper |
getRandom() |
static Random |
getRandom(long seed) |
static int |
hashDouble(double value) |
static int |
hashFloat(float value) |
static int |
nextTwinPrime(int n)
Finds next-largest "twin primes": numbers p and p+2 such that both are prime.
|
static void |
useTestSeed() |
public static final int MAX_INT_SMALLER_TWIN_PRIME
public static void useTestSeed()
public static RandomWrapper getRandom()
public static Random getRandom(long seed)
public static int hashDouble(double value)
Double.hashCode()
would return for the same valuepublic static int hashFloat(float value)
Float.hashCode()
would return for the same valuepublic static int nextTwinPrime(int n)
Finds next-largest "twin primes": numbers p and p+2 such that both are prime. Finds the smallest such p such that the smaller twin, p, is greater than or equal to n. Returns p+2, the larger of the two twins.
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.