Class IntRandomNumberGenerator

java.lang.Object
net.storm.api.commons.IntRandomNumberGenerator

public final class IntRandomNumberGenerator extends Object
A random integer generator that produces values within a specified range.

This class provides an efficient way to generate random integers within an inclusive range [min, max]. It uses Java's Random.ints(int, int) stream to create an iterator that can be called repeatedly for random values.

Unlike Rand, this class is not cryptographically secure and is intended for general-purpose randomization where security is not a concern.

Example usage:


 // Create a generator for values between 1 and 100
 IntRandomNumberGenerator rng = new IntRandomNumberGenerator(1, 100);

 // Generate random values
 int value1 = rng.nextInt();  // Random value in [1, 100]
 int value2 = rng.nextInt();  // Another random value in [1, 100]
 
See Also:
  • Constructor Details

    • IntRandomNumberGenerator

      public IntRandomNumberGenerator(int min, int max)
      Creates a new random number generator that generates random numbers in the inclusive range [min, max].
      Parameters:
      min - the minimum value (inclusive)
      max - the maximum value (inclusive)
  • Method Details

    • nextInt

      public int nextInt()
      Returns the next random number in the configured range.

      The returned value will be between the minimum and maximum values (inclusive) that were specified when this generator was created.

      Returns:
      a random number in the range [min, max]