Class Random

java.lang.Object
com.antithesis.sdk.Random

public final class Random extends Object
The Random class provides methods that request both structured and unstructured randomness from the Antithesis environment.

These methods should not be used to seed a conventional PRNG, and should not have their return values stored and used to make a decision at a later time. Doing either of these things makes it much harder for the Antithesis platform to control the history of your program's execution, and also makes it harder for Antithesis to learn which inputs provided at which times are most fruitful. Instead, you should call a method from the random class every time your program or workload needs to make a decision, at the moment that you need to make the decision.

These methods are also safe to call outside the Antithesis environment, where they will fall back on the Java standard class library implementation.

  • Constructor Details

    • Random

      public Random()
      Default constructor
  • Method Details

    • getRandom

      public static long getRandom()
      Returns a value chosen by Antithesis.

      You should use this value immediately rather than using it later. If you delay, then it is possible for the simulation to branch in between receiving the random data and using it. These branches will have the same random value, which defeats the purpose of branching.

      Similarly, do not use the value to seed a pseudo-random number generator. The PRNG will produce a deterministic sequence of pseudo-random values based on the seed, so if the simulation branches, the PRNG will use the same sequence of values in all branches.

      Returns:
      Random long integer
    • randomChoice

      public static <T> T randomChoice(List<T> list)
      Returns a randomly chosen item from a list of options.

      You should use this value immediately rather than using it later. If you delay, then it is possible for the simulation to branch in between receiving the random data and using it. These branches will have the same random value, which defeats the purpose of branching.

      Similarly, do not use the value to seed a pseudo-random number generator. The PRNG will produce a deterministic sequence of pseudo-random values based on the seed, so if the simulation branches, the PRNG will use the same sequence of values in all branches.

      This function is not purely for convenience. Signaling to the Antithesis platform that you intend to use a random value in a structured way enables it to provide more interesting choices over time.

      Type Parameters:
      T - Type of the array member items
      Parameters:
      list - An array of items to select from
      Returns:
      Randomly selected item from the provided list.