Package com.irurueta.statistics
Class UniformRandomizer
java.lang.Object
com.irurueta.statistics.Randomizer
com.irurueta.statistics.UniformRandomizer
Generates pseudo-random values following a uniform distribution.
-
Field Summary
Fields inherited from class com.irurueta.statistics.Randomizer
DEFAULT_RANDOMIZER_TYPE, USE_SECURE_RANDOM_BY_DEFAULT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
fill
(double[] array, double maxValue) Fills provided array with double precision floating point values within 0.0 and provided maxValue following a uniform distribution.void
fill
(double[] array, double minValue, double maxValue) Fills provided array with uniform double precision floating point values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.void
fill
(float[] array, float maxValue) Fills provided array with floating point values within 0.0 and provided maxValue following a uniform distribution.void
fill
(float[] array, float minValue, float maxValue) Fills provided array with uniform floating point values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.void
fill
(int[] array, int maxValue) Fills provided array with uniform integer values within 0 and provided maxValue following a uniform distribution.void
fill
(int[] array, int minValue, int maxValue) Fills provided array with uniform integer values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.void
fill
(long[] array, long maxValue) Fills provided array with uniform long values within 0 and provided maxValue following a uniform distribution.void
fill
(long[] array, long minValue, long maxValue) Fills provided array with uniform long values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.getType()
Returns the randomizer type of this instance.boolean
Returns next boolean value following a uniform distribution (e.g.double
Returns next random double precision floating-point value within the range 0.0 and 1.0 following a uniform distribution (e.g.double
nextDouble
(double maxValue) Returns next random floating-point value between 0.0 and provided value following a uniform distribution (e.g.double
nextDouble
(double minValue, double maxValue) Returns next random double precision floating-point value between the range of provided values following a uniform distribution (e.g.double[]
nextDoubles
(int length, double maxValue) Returns array of random uniform double precision floating point values within 0.0 and provided maxValue.double[]
nextDoubles
(int length, double minValue, double maxValue) Returns array of random uniform floating point values within provided minValue and maxValue.float
Returns next random floating-point value within the range 0.0 and 1.0 following a uniform distribution (e.g.float
nextFloat
(float maxValue) Returns next random floating-point value between 0.0 and provided value following a uniform distribution (e.g.float
nextFloat
(float minValue, float maxValue) Returns next random floating-point value between the range of provided values following a uniform distribution (e.g.float[]
nextFloats
(int length, float maxValue) Returns array of random uniform floating point values within 0.0 and provided maxValue.float[]
nextFloats
(int length, float minValue, float maxValue) Returns array of random uniform floating point values within provided minValue and maxValue.int
nextInt()
Returns next random integer value within the range of integer values and following a uniform distribution (e.g.int
nextInt
(int maxValue) Returns next random integer value within 0 and provided value following a uniform distribution (e.g.int
nextInt
(int minValue, int maxValue) Returns next random integer value between the range of provided values following a uniform distribution (e.g.int[]
nextInts
(int length, int maxValue) Returns array of random uniform integer values within 0 and provided maxValue.int[]
nextInts
(int length, int minValue, int maxValue) Returns array of random uniform integer values within provided minValue and maxValue.long
nextLong()
Returns next random long value within the range of long values and following a uniform distribution (e.g.long
nextLong
(long maxValue) Returns next random long value within 0 and provided value following a uniform distribution (e.g.long
nextLong
(long minValue, long maxValue) Returns next random long value between the range of provided values following a uniform distribution (e.g.long[]
nextLongs
(int length, long maxValue) Returns array of random uniform long values within 0 and provided maxValue.long[]
nextLongs
(int length, long minValue, long maxValue) Returns array of random uniform long values within provided minValue and maxValue.Methods inherited from class com.irurueta.statistics.Randomizer
create, create, create, create, create, create, fill, fill, fill, fill, fill, getInternalRandom, nextBooleans, nextDoubles, nextFloats, nextInts, nextLongs, setInternalRandom, setSeed
-
Constructor Details
-
UniformRandomizer
public UniformRandomizer()Constructor. Uses defaultRandom
implementation. -
UniformRandomizer
Constructor.- Parameters:
internalRandom
- Internal Random instance in charge of generating pseudo-random values.- Throws:
NullPointerException
- thrown if provided internal random is null.
-
-
Method Details
-
nextBoolean
public boolean nextBoolean()Returns next boolean value following a uniform distribution (e.g. the probability of returning either true or false is 50%).- Specified by:
nextBoolean
in classRandomizer
- Returns:
- Next boolean value following a uniform distribution.
-
nextInt
public int nextInt()Returns next random integer value within the range of integer values and following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Specified by:
nextInt
in classRandomizer
- Returns:
- Next integer value following a uniform distribution.
-
nextInt
public int nextInt(int maxValue) Returns next random integer value within 0 and provided value following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next integer value following a uniform distribution.
- Throws:
IllegalArgumentException
- if provided values is negative.
-
fill
public void fill(int[] array, int maxValue) Fills provided array with uniform integer values within 0 and provided maxValue following a uniform distribution.- Parameters:
array
- Array to be filled.maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if provided value is negative.
-
nextInts
public int[] nextInts(int length, int maxValue) Returns array of random uniform integer values within 0 and provided maxValue.- Parameters:
length
- Length of array to be returned.maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random uniform integers.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
nextInt
public int nextInt(int minValue, int maxValue) Returns next random integer value between the range of provided values following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next integer value following a uniform distribution.
- Throws:
IllegalArgumentException
- Exception thrown if maxValue is smaller or equal than minValue.
-
fill
public void fill(int[] array, int minValue, int maxValue) Fills provided array with uniform integer values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.- Parameters:
array
- Array to be filled.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if maxValue is smaller or equal than minValue.
-
nextInts
public int[] nextInts(int length, int minValue, int maxValue) Returns array of random uniform integer values within provided minValue and maxValue.- Parameters:
length
- Length of array to be returned.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random uniform integers.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
nextLong
public long nextLong()Returns next random long value within the range of long values and following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Specified by:
nextLong
in classRandomizer
- Returns:
- Next long value following a uniform distribution.
-
nextLong
public long nextLong(long maxValue) Returns next random long value within 0 and provided value following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next long value following a uniform distribution.
- Throws:
IllegalArgumentException
- if provided value is negative.
-
fill
public void fill(long[] array, long maxValue) Fills provided array with uniform long values within 0 and provided maxValue following a uniform distribution.- Parameters:
array
- Array to be filled.maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if provided value is negative.
-
nextLongs
public long[] nextLongs(int length, long maxValue) Returns array of random uniform long values within 0 and provided maxValue.- Parameters:
length
- Length of array to be returned.maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random uniform long integers.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
nextLong
public long nextLong(long minValue, long maxValue) Returns next random long value between the range of provided values following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next long value following a uniform distribution.
- Throws:
IllegalArgumentException
- Exception thrown if maxValue is smaller or equal than minValue.
-
fill
public void fill(long[] array, long minValue, long maxValue) Fills provided array with uniform long values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.- Parameters:
array
- Array to be filled.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if maxValue is smaller or equal than minValue.
-
nextLongs
public long[] nextLongs(int length, long minValue, long maxValue) Returns array of random uniform long values within provided minValue and maxValue.- Parameters:
length
- Length of array to be returned.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random uniform integers.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
nextFloat
public float nextFloat()Returns next random floating-point value within the range 0.0 and 1.0 following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Specified by:
nextFloat
in classRandomizer
- Returns:
- Next float value following a uniform distribution between 0.0 and 1.0.
-
nextFloat
public float nextFloat(float maxValue) Returns next random floating-point value between 0.0 and provided value following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next floating-point value following a uniform distribution.
- Throws:
IllegalArgumentException
- if provided value is negative.
-
fill
public void fill(float[] array, float maxValue) Fills provided array with floating point values within 0.0 and provided maxValue following a uniform distribution.- Parameters:
array
- Array to be filled.maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if provided value is negative.
-
nextFloats
public float[] nextFloats(int length, float maxValue) Returns array of random uniform floating point values within 0.0 and provided maxValue.- Parameters:
length
- Length of array to be returned.maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random uniform floating point.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
nextFloat
public float nextFloat(float minValue, float maxValue) Returns next random floating-point value between the range of provided values following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next floating-point value following a uniform distribution.
- Throws:
IllegalArgumentException
- Exception thrown if maxValue is smaller or equal than minValue.
-
fill
public void fill(float[] array, float minValue, float maxValue) Fills provided array with uniform floating point values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.- Parameters:
array
- Array to be filled.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if maxValue is smaller or equal than minValue.
-
nextFloats
public float[] nextFloats(int length, float minValue, float maxValue) Returns array of random uniform floating point values within provided minValue and maxValue.- Parameters:
length
- Length of array to be returned.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random floating point values.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
nextDouble
public double nextDouble()Returns next random double precision floating-point value within the range 0.0 and 1.0 following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Specified by:
nextDouble
in classRandomizer
- Returns:
- Next float value following a uniform distribution between 0.0 and 1.0.
-
nextDouble
public double nextDouble(double maxValue) Returns next random floating-point value between 0.0 and provided value following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next floating-point value following a uniform distribution.
- Throws:
IllegalArgumentException
- if provided value is negative.
-
fill
public void fill(double[] array, double maxValue) Fills provided array with double precision floating point values within 0.0 and provided maxValue following a uniform distribution.- Parameters:
array
- Array to be filled.maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if provided value is negative.
-
nextDoubles
public double[] nextDoubles(int length, double maxValue) Returns array of random uniform double precision floating point values within 0.0 and provided maxValue.- Parameters:
length
- Length of array to be returned.maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random uniform double precision floating point values.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
nextDouble
public double nextDouble(double minValue, double maxValue) Returns next random double precision floating-point value between the range of provided values following a uniform distribution (e.g. each possible value has approximately the same probability to be picked).- Parameters:
minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Next floating-point value following a uniform distribution.
- Throws:
IllegalArgumentException
- Exception thrown if maxValue is smaller or equal than minValue.
-
fill
public void fill(double[] array, double minValue, double maxValue) Fills provided array with uniform double precision floating point values within provided minValue (inclusive) and maxValue (exclusive) following a uniform distribution.- Parameters:
array
- Array to be filled.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Throws:
IllegalArgumentException
- if maxValue is smaller or equal than minValue.
-
nextDoubles
public double[] nextDoubles(int length, double minValue, double maxValue) Returns array of random uniform floating point values within provided minValue and maxValue.- Parameters:
length
- Length of array to be returned.minValue
- Minimum value to be returned (inclusive).maxValue
- Maximum value to be returned (exclusive).- Returns:
- Array of random floating point values.
- Throws:
IllegalArgumentException
- if provided values are zero or negative.
-
getType
Returns the randomizer type of this instance.- Specified by:
getType
in classRandomizer
- Returns:
- Randomizer type.
-