com.rapidminer.tools
Class RandomGenerator

java.lang.Object
  extended by java.util.Random
      extended by com.rapidminer.tools.RandomGenerator
All Implemented Interfaces:
java.io.Serializable

public class RandomGenerator
extends java.util.Random

The global random number generator. This should be used for all random purposes of RapidMiner to ensure that two runs of the same process setup provide the same results.

Author:
Ralf Klinkenberg, Ingo Mierswa
See Also:
Serialized Form

Field Summary
static java.lang.String PARAMETER_LOCAL_RANDOM_SEED
           
static java.lang.String PARAMETER_USE_LOCAL_RANDOM_SEED
           
 
Constructor Summary
RandomGenerator(long seed)
          Initializes the random number generator with the given seed
 
Method Summary
static RandomGenerator getGlobalRandomGenerator()
          Returns the global random number generator.
static RandomGenerator getRandomGenerator(int seed)
          Returns the global random number generator if the seed is negative and a new RandomGenerator with the given seed if the seed is positive or zero.
static RandomGenerator getRandomGenerator(Operator operator)
          This method returns the appropriate RandomGenerator for the user chosen parameter combination
static RandomGenerator getRandomGenerator(Process process, int seed)
          Returns the global random number generator if the seed is negative and a new RandomGenerator with the given seed if the seed is positive or zero.
static java.util.List<ParameterType> getRandomGeneratorParameters(Operator operator)
          This method returns a list of parameters usable to conveniently provide parameters for random generator use within operators
static void init(Process process)
          Instantiates the global random number generator and initializes it with the random number generator seed specified in the global section of the configuration file.
 java.util.Date nextDateInRange(java.util.Date start, java.util.Date end)
          Returns a random date between the given ones.
 double[] nextDoubleArray(int length)
          This method returns a randomly filled array of given length
 double nextDoubleInRange(double lowerBound, double upperBound)
          Returns the next pseudorandom, uniformly distributed double value between lowerBound and upperBound from this random number generator's sequence (exclusive of the interval endpoint values).
 int nextIntInRange(int lowerBound, int upperBound)
          Returns the next pseudorandom, uniformly distributed int value between lowerBound and upperBound from this random number generator's sequence (lower bound inclusive, upper bound exclusive).
 java.util.Set<java.lang.Integer> nextIntSetWithRange(int lowerBound, int upperBound, int size)
          Returns a set of integer within the given range and given size
 long nextLongInRange(long lowerBound, long upperBound)
          returns the next pseudorandom, uniformly distributed long value between lowerBound and upperBound from this random number generator's sequence (exclusive of the interval endpoint values).
 java.lang.String nextString(int length)
          Returns a random String of the given length.
 int randomIndex(double[] probs)
          Returns a randomly selected integer between 0 and the length of the given array.
 
Methods inherited from class java.util.Random
next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAMETER_USE_LOCAL_RANDOM_SEED

public static final java.lang.String PARAMETER_USE_LOCAL_RANDOM_SEED
See Also:
Constant Field Values

PARAMETER_LOCAL_RANDOM_SEED

public static final java.lang.String PARAMETER_LOCAL_RANDOM_SEED
See Also:
Constant Field Values
Constructor Detail

RandomGenerator

public RandomGenerator(long seed)
Initializes the random number generator with the given seed

Method Detail

getGlobalRandomGenerator

public static RandomGenerator getGlobalRandomGenerator()
Returns the global random number generator.


getRandomGenerator

public static RandomGenerator getRandomGenerator(int seed)
Returns the global random number generator if the seed is negative and a new RandomGenerator with the given seed if the seed is positive or zero. This way is is possible to allow for local random seeds. Operators like learners or validation operators should definitely make use of such a local random generator.


getRandomGenerator

public static RandomGenerator getRandomGenerator(Process process,
                                                 int seed)
Returns the global random number generator if the seed is negative and a new RandomGenerator with the given seed if the seed is positive or zero. This way is is possible to allow for local random seeds. Operators like learners or validation operators should definitely make use of such a local random generator.


init

public static void init(Process process)
Instantiates the global random number generator and initializes it with the random number generator seed specified in the global section of the configuration file. Should be invoked before the process starts.


getRandomGeneratorParameters

public static java.util.List<ParameterType> getRandomGeneratorParameters(Operator operator)
This method returns a list of parameters usable to conveniently provide parameters for random generator use within operators

Parameters:
operator - the operator

getRandomGenerator

public static RandomGenerator getRandomGenerator(Operator operator)
                                          throws UndefinedParameterError
This method returns the appropriate RandomGenerator for the user chosen parameter combination

Parameters:
operator -
Throws:
UndefinedParameterError

nextDoubleInRange

public double nextDoubleInRange(double lowerBound,
                                double upperBound)
Returns the next pseudorandom, uniformly distributed double value between lowerBound and upperBound from this random number generator's sequence (exclusive of the interval endpoint values).


nextLongInRange

public long nextLongInRange(long lowerBound,
                            long upperBound)
returns the next pseudorandom, uniformly distributed long value between lowerBound and upperBound from this random number generator's sequence (exclusive of the interval endpoint values).


nextIntInRange

public int nextIntInRange(int lowerBound,
                          int upperBound)
Returns the next pseudorandom, uniformly distributed int value between lowerBound and upperBound from this random number generator's sequence (lower bound inclusive, upper bound exclusive).


nextString

public java.lang.String nextString(int length)
Returns a random String of the given length.


randomIndex

public int randomIndex(double[] probs)
Returns a randomly selected integer between 0 and the length of the given array. Uses the given probabilities to determine the index, all values in this array must sum up to 1.


nextDoubleArray

public double[] nextDoubleArray(int length)
This method returns a randomly filled array of given length

Parameters:
length - the length of the returned array
Returns:
the filled array

nextDateInRange

public java.util.Date nextDateInRange(java.util.Date start,
                                      java.util.Date end)
Returns a random date between the given ones.


nextIntSetWithRange

public java.util.Set<java.lang.Integer> nextIntSetWithRange(int lowerBound,
                                                            int upperBound,
                                                            int size)
Returns a set of integer within the given range and given size



Copyright © 2001-2009 by Rapid-I