eaLib API Docs
Last Modified : January 7 2002

mss.ea.core
Class RandomUtil

java.lang.Object
  |
  +--mss.ea.core.RandomUtil

public class RandomUtil
extends java.lang.Object

Utility methods for working with random objects.

Since:
0.1
Version:
0.1 (08-09-2001)
Author:
Andreas Rummler

Constructor Summary
RandomUtil()
           
 
Method Summary
static double randomDouble(double bound)
          Random double value.
static double randomDouble(double lowerBound, double upperBound)
          Random double value.
static float randomFloat(float bound)
          Random float value.
static float randomFloat(float lowerBound, float upperBound)
          Random float value.
static int randomInt(int bound)
          Random integer value.
static int randomInt(int lowerBound, int upperBound)
          Random integer value.
static int[] randomIntegerSample(int sampleNumber, int samplePool)
          Choice of n random numbers from N possible.
static int[] randomIntegerSample(int sampleNumber, int samplePool, boolean zeroInc)
          Choice of n random numbers from N possible.
static int[] randomIntSequence(int size)
          Generates a random sequence of integers from 0 to the given integer (exclusive).
static long randomLong(long bound)
          Random long value.
static long randomLong(long lowerBound, long upperBound)
          Random long value.
static java.lang.String randomString()
          Produces a random string with a random length.
static java.lang.String randomString(byte b)
          Produces a random string.
static java.lang.String randomString(int i)
          Produces a random string.
static java.lang.String randomWord()
          Produces a random "word".
static java.lang.String randomWord(byte b)
          Produces a random "word".
static java.lang.String randomWord(int i)
          Produces a random "word".
static void scramble(java.util.List list)
          Scrambles a list.
static void scramble(java.util.List list, int sCount)
          Swaps two random elements of a list n times.
static void scramble(java.lang.Object array)
          Scrambles an array.
static void scramble(java.lang.Object array, int sCount)
          Swaps two random elements of an array n times.
static void scrambleArray(java.lang.Object[] array)
          Deprecated. replaced by scramble
static void scrambleArray(java.lang.Object[] array, int sCount)
          Deprecated. replaced by scramble
static void scrambleList(java.util.List list)
          Deprecated. replaced by scramble
static void scrambleList(java.util.List list, int sCount)
          Deprecated. replaced by scramble
static void setSeed(long l)
          Setting of the random seeds.
static void swap(java.util.List list)
          Swaps two random elements of a list.
static void swap(java.lang.Object array)
          Swaps two random elements of an array.
static void updateSeed()
          Update of random seed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomUtil

public RandomUtil()
Method Detail

updateSeed

public static void updateSeed()
Update of random seed. The seed is overwritten with the current system time.

setSeed

public static void setSeed(long l)
Setting of the random seeds. The seed can be set to a specific value using this method to provide the possibility to generate uniform sequences of random numbers.
Parameters:
l - new random seed

randomDouble

public static double randomDouble(double bound)
Random double value. The return value lies between 0.0 and the given bound.
Parameters:
bound - bound
Returns:
random double

randomDouble

public static double randomDouble(double lowerBound,
                                  double upperBound)
Random double value. The return value lies between lowerBound and upperBound. The method will return 0.0 silently if lowerBound >= upperBound.
Parameters:
lowerBound - lower bound
upperBound - upper bound
Returns:
random double

randomFloat

public static float randomFloat(float bound)
Random float value. The return value lies between 0.0 and the given bound.
Parameters:
bound - bound
Returns:
random float

randomFloat

public static float randomFloat(float lowerBound,
                                float upperBound)
Random float value. The return value lies between lowerBound and upperBound. The method will return 0.0 silently if lowerBound >= upperBound.
Parameters:
lowerBound - lower bound
upperBound - upper bound
Returns:
random float

randomInt

public static int randomInt(int bound)
Random integer value. The return value lies between 0 (inclusive) and the given bound (exclusive). This is also valid for negative bounds.
Parameters:
bound - bound
Returns:
random integer

randomInt

public static int randomInt(int lowerBound,
                            int upperBound)
Random integer value. The return value lies between lowerBound (inclusive) and upperBound (exclusive). The method will return 0 silently if lowerBound >= upperBound.
Parameters:
lowerBound - lower bound
upperBound - upper bound
Returns:
random integer

randomLong

public static long randomLong(long bound)
Random long value. The return value lies between 0 and the given bound.
Parameters:
bound - bound
Returns:
random long

randomLong

public static long randomLong(long lowerBound,
                              long upperBound)
Random long value. The return value lies between lowerBound and upperBound. The method will return 0 silently if lowerBound >= upperBound.
Parameters:
lowerBound - lower bound
upperBound - upper bound
Returns:
random long

randomString

public static java.lang.String randomString()
Produces a random string with a random length. The can have a maximal length of 127 characters.
Returns:
random string
See Also:
randomString( byte )

randomString

public static java.lang.String randomString(byte b)
Produces a random string. The string can have a maximal length of 127 characters. In case that the given parameter is negative a random string of length 1 is generated. The produced characters have ASCII values between #32 and #126. The range from #161 to #255 (which is also printable) is not supported (yet).
Parameters:
b - length of random string
Returns:
random string

randomString

public static java.lang.String randomString(int i)
Produces a random string. The is implemented for convenience reasons.
Parameters:
i - length of string
Returns:
random string
See Also:
randomString( byte )

randomWord

public static java.lang.String randomWord()
Produces a random "word". Same functionality like randomString(), but produces a string containing only lower case characters.
Returns:
random string

randomWord

public static java.lang.String randomWord(byte b)
Produces a random "word". Same functionality like randomString( byte ), but produces a string containing only lower case characters.
Parameters:
b - length of string
Returns:
random string

randomWord

public static java.lang.String randomWord(int i)
Produces a random "word". Same functionality like randomString( int ), but produces a string containing only lower case characters.
Parameters:
i - length of string
Returns:
random string

randomIntegerSample

public static int[] randomIntegerSample(int sampleNumber,
                                        int samplePool)
                                 throws java.lang.IllegalArgumentException
Choice of n random numbers from N possible. The original code was written by Laurentiu Cristofor (laur72_98@yahoo.com). This method selects numbers between 1 (inclusive) and samplePool (inclusive).
Parameters:
sampleNumber - number of selections
samplePool - upper bound
Returns:
array with selected numbers
Throws:
java.lang.IllegalArgumentException - thrown, if N < 0 or N < n

randomIntegerSample

public static int[] randomIntegerSample(int sampleNumber,
                                        int samplePool,
                                        boolean zeroInc)
                                 throws java.lang.IllegalArgumentException
Choice of n random numbers from N possible. The original code was written by Laurentiu Cristofor (laur72_98@yahoo.com). This method selects numbers depending on zeroInc. In case of zeroInc = true, the range of values is from 0 (inclusive) to samplePool - 1 (inclusive), else from 1 (inclusive) to samplePool (inclusive).
Parameters:
sampleNumber - number of selections
samplePool - upper bound
zeroInc - selection of range of values
Returns:
array with selected numbers
Throws:
java.lang.IllegalArgumentException - thrown, if N < 0, or N < n

scrambleList

public static void scrambleList(java.util.List list)
Deprecated. replaced by scramble

Swaps two random elements of a list.
Parameters:
list - list with n>1 elements

scrambleList

public static void scrambleList(java.util.List list,
                                int sCount)
Deprecated. replaced by scramble

Swap two random elements of a list n times.
Parameters:
list - list with n > 1 elements
sCount - number of swaps

scrambleArray

public static void scrambleArray(java.lang.Object[] array)
Deprecated. replaced by scramble

Swaps two random elements of an object array.
Parameters:
array - array with n>1 elements

scrambleArray

public static void scrambleArray(java.lang.Object[] array,
                                 int sCount)
Deprecated. replaced by scramble

Swap two random elements of an object array n times.
Parameters:
array - array with n > 1 elements
sCount - number of swaps

randomIntSequence

public static int[] randomIntSequence(int size)
Generates a random sequence of integers from 0 to the given integer (exclusive). Each number occurs only one time.
Parameters:
size - length of the integer sequence
Returns:
sequence of integers

scramble

public static void scramble(java.util.List list)
Scrambles a list.
Parameters:
list - list with n > 1 elements

scramble

public static void scramble(java.util.List list,
                            int sCount)
Swaps two random elements of a list n times.
Parameters:
list - list with n > 1 elements
sCount - number of swaps

scramble

public static void scramble(java.lang.Object array)
Scrambles an array.
Parameters:
array - array with n > 1 elements

scramble

public static void scramble(java.lang.Object array,
                            int sCount)
Swaps two random elements of an array n times.
Parameters:
array - array with n > 1 elements
sCount - number of swaps

swap

public static void swap(java.util.List list)
Swaps two random elements of a list.
Parameters:
list - list with n > 1 elements

swap

public static void swap(java.lang.Object array)
Swaps two random elements of an array.
Parameters:
array - array with n > 1 objects

eaLib API Docs
Last Modified : January 7 2002

Copyright © 2000-2001 Technical University of Ilmenau, Department ESS