Package jline.util

Class RandomManager

  • All Implemented Interfaces:

    
    public class RandomManager
    
                        

    Centralized random number generator management for reproducible, thread-safe random number generation. This class ensures that: - All random number generation uses MersenneTwister - Setting a master seed produces deterministic results across all threads - Each thread gets its own MersenneTwister instance with a deterministic sub-seed - Parallel execution is reproducible when using the same master seed

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public static volatile int masterSeed
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomManager()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static int getMasterSeed() Gets the current master seed.
      static void setMasterSeed(int seed) Sets the master seed that controls all random number generation.
      static MersenneTwister getThreadRandom() Gets a thread-specific MersenneTwister instance.
      static Random getThreadRandomAsRandom() Gets a thread-specific Random instance for compatibility with java.util.Random.
      static MersenneTwister getSolverRandom(String solverId) Gets a solver-specific MersenneTwister instance.
      static MersenneTwister getParallelRandom(String solverId, int threadOffset) Creates a MersenneTwister instance for parallel processing with a thread offset.
      static double nextDouble() Generates a random double value in [0.0, 1.0) using the thread-specific generator.
      static double nextGaussian() Generates a random Gaussian (normal) distributed double value using the thread-specific generator.
      static int nextInt(int bound) Generates a random integer between 0 (inclusive) and the specified value (exclusive).
      static void reset() Resets all random number generators to use the current master seed.
      static MersenneTwister newInstance() Gets a fresh MersenneTwister instance with the master seed.
      static int generateRandomSeed() Generates a random seed using the same formula as SolverOptions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RandomManager

        RandomManager()
    • Method Detail

      • getMasterSeed

         static int getMasterSeed()

        Gets the current master seed.

        Returns:

        the current master seed

      • setMasterSeed

         static void setMasterSeed(int seed)

        Sets the master seed that controls all random number generation. This ensures reproducible results across all threads and solvers.

        Parameters:
        seed - the master seed value
      • getThreadRandom

         static MersenneTwister getThreadRandom()

        Gets a thread-specific MersenneTwister instance. Each thread gets its own generator with a deterministic seed derived from the master seed.

        Returns:

        thread-specific MersenneTwister instance

      • getThreadRandomAsRandom

         static Random getThreadRandomAsRandom()

        Gets a thread-specific Random instance for compatibility with java.util.Random. This wraps the MersenneTwister to provide java.util.Random compatibility.

        Returns:

        thread-specific Random instance backed by MersenneTwister

      • getSolverRandom

         static MersenneTwister getSolverRandom(String solverId)

        Gets a solver-specific MersenneTwister instance. Each solver gets its own generator with a deterministic seed.

        Parameters:
        solverId - unique identifier for the solver
        Returns:

        solver-specific MersenneTwister instance

      • getParallelRandom

         static MersenneTwister getParallelRandom(String solverId, int threadOffset)

        Creates a MersenneTwister instance for parallel processing with a thread offset. This ensures different threads in parallel algorithms get different but reproducible sequences.

        Parameters:
        solverId - unique identifier for the solver
        threadOffset - offset for this thread (e.g.
        Returns:

        MersenneTwister instance with deterministic seed

      • nextDouble

         static double nextDouble()

        Generates a random double value in [0.0, 1.0) using the thread-specific generator. For backward compatibility, this uses the same ThreadLocal pattern as original ThreadLocalRandom.

        Returns:

        random double value

      • nextGaussian

         static double nextGaussian()

        Generates a random Gaussian (normal) distributed double value using the thread-specific generator. For backward compatibility, this uses the same ThreadLocal pattern as original ThreadLocalRandom.

        Returns:

        random Gaussian-distributed double value

      • nextInt

         static int nextInt(int bound)

        Generates a random integer between 0 (inclusive) and the specified value (exclusive).

        Parameters:
        bound - the upper bound (exclusive).
        Returns:

        random integer in range [0, bound)

      • reset

         static void reset()

        Resets all random number generators to use the current master seed. This can be called to ensure fresh random sequences.

      • newInstance

         static MersenneTwister newInstance()

        Gets a fresh MersenneTwister instance with the master seed. Useful for creating new independent random streams.

        Returns:

        new MersenneTwister instance with master seed

      • generateRandomSeed

         static int generateRandomSeed()

        Generates a random seed using the same formula as SolverOptions.

        Returns:

        random seed value