Package com.xceptance.xlt.api.util
Class XltRandom
- java.lang.Object
-
- com.xceptance.xlt.api.util.XltRandom
-
public class XltRandom extends java.lang.ObjectUtility class for random numbers and strings.Note that this class maintains a separate random number generator instance per thread.
-
-
Constructor Summary
Constructors Constructor Description XltRandom()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.RandomgetRandom()Returns the random number generator singleton.static intgetRandom(int[] data)Returns a random number based on a given array of integers.static longgetSeed()Returns the seed that was used to initialize the current thread's random number generator.static booleannextBoolean()static booleannextBoolean(int trueCaseProbability)Returns a random boolean value where the probability thattrueis returned is given as parameter.static voidnextBytes(byte[] bytes)static doublenextDouble()static floatnextFloat()static doublenextGaussian()static intnextInt()static intnextInt(int n)static intnextInt(int minimum, int maximum)Returns a pseudo-random, uniformly distributed number that lies within the range from [minimum, maximum].static intnextIntWithDeviation(int base, int deviation)Returns a pseudo-random, uniformly distributed number that lies within the range from [base - deviation, base + deviation].static longnextLong()static voidreseed()Reinitializes the current thread's random number generator with a new seed value that is derived from the current seed.static voidsetSeed(long seed)Reinitializes the current thread's random number generator with the given seed value.
-
-
-
Method Detail
-
setSeed
public static void setSeed(long seed)
Reinitializes the current thread's random number generator with the given seed value. Use this method together withgetSeed()to reset the random number generator to a defined state in which it will produce the same sequence of random numbers.- Parameters:
seed- the seed
-
getSeed
public static long getSeed()
Returns the seed that was used to initialize the current thread's random number generator. Use this method together withsetSeed(long)to reset the random number generator to a defined state in which it will produce the same sequence of random numbers.- Returns:
- the seed
-
reseed
public static void reseed()
Reinitializes the current thread's random number generator with a new seed value that is derived from the current seed.
-
nextBoolean
public static boolean nextBoolean()
- See Also:
Random.nextBoolean()
-
nextBoolean
public static boolean nextBoolean(int trueCaseProbability)
Returns a random boolean value where the probability thattrueis returned is given as parameter. The probability value has to be specified in the range of 0-100.- ≤ 0 - never returns
true - 1..99 - the probability of
truebeing returned - ≥ 100 - always returns
true
- Parameters:
trueCaseProbability- the probability oftruebeing returned- Returns:
- a random boolean value
- ≤ 0 - never returns
-
nextBytes
public static void nextBytes(byte[] bytes)
- See Also:
Random.nextBytes(byte[])
-
nextDouble
public static double nextDouble()
- See Also:
Random.nextDouble()
-
nextFloat
public static float nextFloat()
- See Also:
Random.nextFloat()
-
nextGaussian
public static double nextGaussian()
- See Also:
Random.nextGaussian()
-
nextInt
public static int nextInt()
- See Also:
Random.nextInt()
-
nextInt
public static int nextInt(int n)
- See Also:
Random.nextInt(int)
-
nextLong
public static long nextLong()
- See Also:
Random.nextLong()
-
getRandom
public static java.util.Random getRandom()
Returns the random number generator singleton.- Returns:
- the random number generator
-
getRandom
public static int getRandom(int[] data)
Returns a random number based on a given array of integers.- Parameters:
data- an array with integers to choose from- Returns:
- a random number from the array
- Throws:
java.lang.ArrayIndexOutOfBoundsException- will be thrown when an empty array is given
-
nextIntWithDeviation
public static int nextIntWithDeviation(int base, int deviation)Returns a pseudo-random, uniformly distributed number that lies within the range from [base - deviation, base + deviation].- Parameters:
base- base integer for the numberdeviation- the maximum deviation from base- Returns:
- a random number
-
nextInt
public static int nextInt(int minimum, int maximum)Returns a pseudo-random, uniformly distributed number that lies within the range from [minimum, maximum].- Parameters:
minimum- the minimum value (inclusive)maximum- the maximum value (inclusive)- Returns:
- a random number
-
-