Package mocka.random
Class RandomProvider
java.lang.Object
mocka.random.RandomProvider
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 TypeMethodDescriptionbooleanGenerates a random boolean value.doublegetDouble(double size) Generates a random double between 0 (inclusive) and size (exclusive).doublegetDouble(double min, double max) Generates a random double within the specified range.floatgetFloat(float size) Generates a random float between 0 (inclusive) and size (exclusive).floatgetFloat(float min, float max) Generates a random float within the specified range.doublegetGaussian(double mean, double stdev) Generates a random double from a Gaussian (normal) distribution.static RandomProviderintgetInt(int size) Generates a random integer between 0 (inclusive) and size (exclusive).intgetInt(int min, int max) Generates a random integer within the specified range.longgetLong(long size) Generates a random long between 0 (inclusive) and size (exclusive).longgetLong(long min, long max) Generates a random long within the specified range.<T> TgetNextIdx(T size) Generates a random index value within the bounds of the given size.
-
Method Details
-
getInstance
-
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 distributionstdev- the standard deviation (spread) of the distribution- Returns:
- a random double following the specified Gaussian distribution
-