Package mocka.random

Class RandomProvider

java.lang.Object
mocka.random.RandomProvider

public class RandomProvider extends Object
Thread-safe singleton provider for generating random values.

This class serves as a facade for random number generation, delegating to ThreadLocalRandomIndexProvider for thread-safe random value generation. It provides convenient methods for generating various primitive types with different range constraints.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Generates a random boolean value.
    double
    getDouble(double size)
    Generates a random double between 0 (inclusive) and size (exclusive).
    double
    getDouble(double min, double max)
    Generates a random double within the specified range.
    float
    getFloat(float size)
    Generates a random float between 0 (inclusive) and size (exclusive).
    float
    getFloat(float min, float max)
    Generates a random float within the specified range.
    double
    getGaussian(double mean, double stdev)
    Generates a random double from a Gaussian (normal) distribution.
     
    int
    getInt(int size)
    Generates a random integer between 0 (inclusive) and size (exclusive).
    int
    getInt(int min, int max)
    Generates a random integer within the specified range.
    long
    getLong(long size)
    Generates a random long between 0 (inclusive) and size (exclusive).
    long
    getLong(long min, long max)
    Generates a random long within the specified range.
    <T> T
    getNextIdx(T size)
    Generates a random index value within the bounds of the given size.
     

    Methods inherited from class java.lang.Object

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

    • getInstance

      public static RandomProvider getInstance()
    • getRandom

      public Random getRandom()
    • getNextIdx

      public <T> T getNextIdx(T size)
      Generates a random index value within the bounds of the given size.
      Type Parameters:
      T - the numeric type (Integer, Long, etc.)
      Parameters:
      size - the upper bound (exclusive) for the random index
      Returns:
      a random value between 0 (inclusive) and size (exclusive)
    • getBoolean

      public boolean getBoolean()
      Generates a random boolean value.
      Returns:
      a random boolean (true or false with equal probability)
    • getInt

      public int getInt(int size)
      Generates a random integer between 0 (inclusive) and size (exclusive).
      Parameters:
      size - the upper bound (exclusive)
      Returns:
      a random integer in the range [0, size)
    • getInt

      public int getInt(int min, int max)
      Generates a random integer within the specified range.
      Parameters:
      min - the lower bound (inclusive)
      max - the upper bound (exclusive)
      Returns:
      a random integer in the range [min, max)
    • getLong

      public long getLong(long size)
      Generates a random long between 0 (inclusive) and size (exclusive).
      Parameters:
      size - the upper bound (exclusive)
      Returns:
      a random long in the range [0, size)
    • getLong

      public long getLong(long min, long max)
      Generates a random long within the specified range.
      Parameters:
      min - the lower bound (inclusive)
      max - the upper bound (exclusive)
      Returns:
      a random long in the range [min, max)
    • getFloat

      public float getFloat(float size)
      Generates a random float between 0 (inclusive) and size (exclusive).
      Parameters:
      size - the upper bound (exclusive)
      Returns:
      a random float in the range [0, size)
    • getFloat

      public float getFloat(float min, float max)
      Generates a random float within the specified range.
      Parameters:
      min - the lower bound (inclusive)
      max - the upper bound (exclusive)
      Returns:
      a random float in the range [min, max)
    • getDouble

      public double getDouble(double size)
      Generates a random double between 0 (inclusive) and size (exclusive).
      Parameters:
      size - the upper bound (exclusive)
      Returns:
      a random double in the range [0, size)
    • getDouble

      public double getDouble(double min, double max)
      Generates a random double within the specified range.
      Parameters:
      min - the lower bound (inclusive)
      max - the upper bound (exclusive)
      Returns:
      a random double in the range [min, max)
    • getGaussian

      public double getGaussian(double mean, double stdev)
      Generates a random double from a Gaussian (normal) distribution.

      The generated values follow a bell curve centered around the mean, with spread determined by the standard deviation.

      Parameters:
      mean - the mean (center) of the Gaussian distribution
      stdev - the standard deviation (spread) of the distribution
      Returns:
      a random double following the specified Gaussian distribution