Class XltRandom

java.lang.Object
com.xceptance.xlt.api.util.XltRandom

public class XltRandom extends Object
Utility class for random numbers and strings.

Note that this class maintains a separate random number generator instance per thread.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Random
    Returns the random number generator singleton.
    static int
    getRandom(int[] data)
    Returns a random number based on a given array of integers.
    static long
    Returns the seed that was used to initialize the current thread's random number generator.
    static boolean
     
    static boolean
    nextBoolean(int trueCaseProbability)
    Returns a random boolean value where the probability that true is returned is given as parameter.
    static void
    nextBytes(byte[] bytes)
     
    static double
     
    static float
     
    static double
     
    static int
     
    static int
    nextInt(int n)
     
    static int
    nextInt(int minimum, int maximum)
    Returns a pseudo-random, uniformly distributed number that lies within the range from [minimum, maximum].
    static int
    nextIntWithDeviation(int base, int deviation)
    Returns a pseudo-random, uniformly distributed number that lies within the range from [base - deviation, base + deviation].
    static long
     
    static void
    Reinitializes the current thread's random number generator with a new seed value that is derived from the current seed.
    static void
    setSeed(long seed)
    Reinitializes the current thread's random number generator with the given seed value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 with getSeed() 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 with setSeed(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 that true is 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 true being returned
      • ≥ 100 - always returns true
      Parameters:
      trueCaseProbability - the probability of true being returned
      Returns:
      a random boolean value
    • 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

      public static 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:
      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 number
      deviation - 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