Class Rand

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

public class Rand extends Object
Provides cryptographically secure random number generation utilities.

This class uses SecureRandom with the SHA1PRNG algorithm to generate random values. All methods are synchronized to ensure thread-safety.

Unlike IntRandomNumberGenerator, this class provides a static utility interface and uses cryptographically secure randomization, making it suitable for security-sensitive operations.

Example usage:


 // Generate a random integer in a range
 int randomDelay = Rand.nextInt(500, 1500);

 // Generate any random integer
 int randomValue = Rand.nextInt();

 // Generate a random boolean
 if (Rand.nextBool()) {
     // 50% chance of executing this block
 }
 
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Returns a random boolean value.
    static int
    Returns a random integer from the full range of possible integer values.
    static int
    nextInt(int min, int max)
    Returns a random integer within the specified inclusive range.

    Methods inherited from class java.lang.Object

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

    • Rand

      public Rand()
  • Method Details

    • nextInt

      public static int nextInt(int min, int max)
      Returns a random integer within the specified inclusive range.

      This method is thread-safe and uses cryptographically secure randomization.

      Parameters:
      min - the minimum value (inclusive)
      max - the maximum value (inclusive)
      Returns:
      a random integer between min and max (inclusive)
    • nextInt

      public static int nextInt()
      Returns a random integer from the full range of possible integer values.

      This method is thread-safe and uses cryptographically secure randomization.

      Returns:
      a random integer value
    • nextBool

      public static boolean nextBool()
      Returns a random boolean value.

      This method is thread-safe and uses cryptographically secure randomization. It has an equal probability of returning true or false.

      Returns:
      a random boolean value