Class RandomUtils.DataGenerator
- java.lang.Object
-
- org.apache.commons.math4.random.RandomUtils.DataGenerator
-
- Enclosing class:
- RandomUtils
public static class RandomUtils.DataGenerator extends java.lang.ObjectVarious random data generation routines.
-
-
Method Summary
Modifier and Type Method Description java.lang.StringnextHexString(int len, boolean useSha1)Generates a random string of hex characters of lengthlen.longnextLong(long lower, long upper)Generates a uniformly distributed random long integer betweenlowerandupper(endpoints included).doublenextUniform(double lower, double upper)Generates a uniformly distributed random value from the open interval(lower, upper)(i.e., endpoints excluded).doublenextUniform(double lower, double upper, boolean lowerInclusive)Generates a uniformly distributed random value from the interval(lower, upper)or the interval[lower, upper).
-
-
-
Method Detail
-
nextHexString
public java.lang.String nextHexString(int len, boolean useSha1)Generates a random string of hex characters of lengthlen. Algorithm Description: how hexadecimal strings are generated depends on the value of theuseSha1argument.- If
useSha1 == false, a 2-step process is used:-
len / 2 + 1binary bytes are generated using the underlying generator. - Each binary byte is translated into 2 hex digits.
-
-
If
useSha1 == true, hex strings are generated in 40-byte segments using a 3-step process:- 20 random bytes are generated using the underlying generator.
- SHA-1 hash is applied to yield a 20-byte binary digest.
- Each byte of the binary digest is converted to 2 hex digits.
- Parameters:
len- Length of the generated string.useSha1- Whether to use a digest. Iftrue(resp.false), the 3-step (resp. 2-step) process will be used.- Returns:
- the random string.
- Throws:
NotStrictlyPositiveException- iflen <= 0.
- If
-
nextLong
public long nextLong(long lower, long upper)Generates a uniformly distributed random long integer betweenlowerandupper(endpoints included).- Parameters:
lower- Lower bound for generated long integer.upper- Upper bound for generated long integer.- Returns:
- a random long integer greater than or equal to
lowerand less than or equal toupper - Throws:
NumberIsTooLargeException- iflower >= upper
-
nextUniform
public double nextUniform(double lower, double upper)Generates a uniformly distributed random value from the open interval(lower, upper)(i.e., endpoints excluded).Definition: Uniform Distribution
lowerandupper - lowerare the location and scale parameters, respectively.Algorithm Description: scales the output of Random.nextDouble(), but rejects 0 values (i.e., will generate another random double if Random.nextDouble() returns 0). This is necessary to provide a symmetric output interval (both endpoints excluded).
- Parameters:
lower- Lower bound of the support (excluded).upper- Upper bound of the support (excluded).- Returns:
- a uniformly distributed random value between lower and upper (both excluded).
- Throws:
NumberIsTooLargeException- iflower >= upper.NotFiniteNumberException- if one of the bounds is infinite.NotANumberException- if one of the bounds is NaN.
-
nextUniform
public double nextUniform(double lower, double upper, boolean lowerInclusive)Generates a uniformly distributed random value from the interval(lower, upper)or the interval[lower, upper). The lower bound is thus optionally included, while the upper bound is always excluded.Definition: Uniform Distribution
lowerandupper - lowerare the location and scale parameters, respectively.Algorithm Description: if the lower bound is excluded, scales the output of "nextDouble()", but rejects 0 values (i.e. it will generate another random double if "nextDouble()" returns 0). This is necessary to provide a symmetric output interval (both endpoints excluded).
- Parameters:
lower- Lower bound of the support.upper- Exclusive upper bound of the support.lowerInclusive-trueif the lower bound is inclusive.- Returns:
- a uniformly distributed random value in the
(lower, upper)interval, iflowerInclusiveisfalse, or in the[lower, upper)interval, iflowerInclusiveistrue. - Throws:
NumberIsTooLargeException- iflower >= upper.NotFiniteNumberException- if one of the bounds is infinite.NotANumberException- if one of the bounds is NaN.
-
-