org.apache.mahout.common
Class RandomUtils

java.lang.Object
  extended by org.apache.mahout.common.RandomUtils

public final class RandomUtils
extends java.lang.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.

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 java.util.Random getRandom()
           
static java.util.Random getRandom(long seed)
           
static int hashDouble(double value)
           
static int hashFloat(float value)
           
static int hashLong(long 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

MAX_INT_SMALLER_TWIN_PRIME

public static final int MAX_INT_SMALLER_TWIN_PRIME
The largest prime less than 231-1 that is the smaller of a twin prime pair.

See Also:
Constant Field Values
Method Detail

useTestSeed

public static void useTestSeed()

getRandom

public static java.util.Random getRandom()

getRandom

public static java.util.Random getRandom(long seed)

longSeedtoBytes

public static byte[] longSeedtoBytes(long seed)

seedBytesToLong

public static long seedBytesToLong(byte[] seed)

hashDouble

public static int hashDouble(double value)
Returns:
what Double.hashCode() would return for the same value

hashFloat

public static int hashFloat(float value)
Returns:
what Float.hashCode() would return for the same value

hashLong

public static int hashLong(long value)

nextTwinPrime

public 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.


nextPrime

public static int nextPrime(int n)

Finds smallest prime p such that p is greater than or equal to n.


isNotPrime

public static boolean isNotPrime(int n)
Returns:
true iff n is not a prime


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.