Package com.xceptance.xlt.api.util
Class XltRandom
java.lang.Object
com.xceptance.xlt.api.util.XltRandom
Utility class for random numbers and strings.
Note that this class maintains a separate random number generator instance per thread.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RandomReturns 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 booleanstatic booleannextBoolean(int trueCaseProbability) Returns a random boolean value where the probability thattrueis returned is given as parameter.static voidnextBytes(byte[] bytes) static doublestatic floatstatic doublestatic 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.
-
Constructor Details
-
XltRandom
public XltRandom()
-
-
Method Details
-
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:
-
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:
-
nextDouble
public static double nextDouble()- See Also:
-
nextFloat
public static float nextFloat()- See Also:
-
nextGaussian
public static double nextGaussian()- See Also:
-
nextInt
public static int nextInt()- See Also:
-
nextInt
public static int nextInt(int n) - See Also:
-
nextLong
public static long nextLong()- See Also:
-
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:
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
-