|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mahout.common.RandomUtils
public final class RandomUtils
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.
This class is increasingly incorrectly named as it also includes other mathematical utility methods.
Field Summary | |
---|---|
static int |
MAX_INT_SMALLER_TWIN_PRIME
The largest prime less than 231-1 that is the smaller of a twin prime pair. |
Method Summary | |
---|---|
static Random |
getRandom()
|
static Random |
getRandom(long seed)
|
static int |
hashDouble(double value)
|
static int |
hashFloat(float value)
|
static boolean |
isNotPrime(int n)
|
static byte[] |
longSeedtoBytes(long seed)
|
static int |
nextPrime(int n)
Finds smallest prime p such that p is greater than or equal to n. |
static int |
nextTwinPrime(int n)
Finds next-largest "twin primes": numbers p and p+2 such that both are prime. |
static long |
seedBytesToLong(byte[] seed)
|
static void |
useTestSeed()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_INT_SMALLER_TWIN_PRIME
Method Detail |
---|
public static void useTestSeed()
public static Random getRandom()
public static Random getRandom(long seed)
public static byte[] longSeedtoBytes(long seed)
public static long seedBytesToLong(byte[] 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.
public static int nextPrime(int n)
Finds smallest prime p such that p is greater than or equal to n.
public static boolean isNotPrime(int n)
true
iff n is not a prime
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |