Top Description Methods
org.apache.commons.math3.random

public Interface RandomData

Known Direct Implementers
org.apache.commons.math3.random.RandomDataGenerator, org.apache.commons.math3.random.RandomDataImpl
Annotations
@Deprecated
Imports
java.util.Collection, org.apache.commons.math3.exception.NotANumberException, .NotFiniteNumberException, .NotStrictlyPositiveException, .NumberIsTooLargeException

Deprecated

to be removed in 4.0. Use RandomDataGenerator directly

Random data generation utilities.

Method Summary

Modifier and TypeMethod and Description
public double

Returns:

a random value following the specified exponential distribution
nextExponential
(double
the mean of the distribution
mean
)

Generates a random value from the exponential distribution with specified mean.

public double

Returns:

a random value following the specified Gaussian distribution
nextGaussian
(double
the mean of the distribution
mu
,
double
the standard deviation of the distribution
sigma
)

Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.

public String

Returns:

a random string of hex characters of length len
nextHexString
(int
the length of the string to be generated
len
)

Generates a random string of hex characters of length len.

public int

Returns:

a random integer greater than or equal to lower and less than or equal to upper
nextInt
(int
lower bound for generated integer
lower
,
int
upper bound for generated integer
upper
)

Generates a uniformly distributed random integer between lower and upper (endpoints included).

public long

Returns:

a random long integer greater than or equal to lower and less than or equal to upper
nextLong
(long
lower bound for generated long integer
lower
,
long
upper bound for generated long integer
upper
)

Generates a uniformly distributed random long integer between lower and upper (endpoints included).

public int[]

Returns:

a random k-permutation of n, as an array of integers
nextPermutation
(int
the domain of the permutation
n
,
int
the size of the permutation
k
)

Generates an integer array of length k whose entries are selected randomly, without repetition, from the integers 0, ..., n - 1 (inclusive).

public long

Returns:

a random value following the specified Poisson distribution
nextPoisson
(double
the mean of the Poisson distribution
mean
)

Generates a random value from the Poisson distribution with the given mean.

public Object[]

Returns:

a random sample of k elements from c
nextSample
(Collection<?>
the collection to be sampled
c
,
int
the size of the sample
k
)

Returns an array of k objects selected randomly from the Collection c.

public String

Returns:

a random string of hex characters of length len
nextSecureHexString
(int
the length of the string to be generated
len
)

Generates a random string of hex characters from a secure random sequence.

public int

Returns:

a random integer greater than or equal to lower and less than or equal to upper.
nextSecureInt
(int
lower bound for generated integer
lower
,
int
upper bound for generated integer
upper
)

Generates a uniformly distributed random integer between lower and upper (endpoints included) from a secure random sequence.

public long

Returns:

a random long integer greater than or equal to lower and less than or equal to upper.
nextSecureLong
(long
lower bound for generated integer
lower
,
long
upper bound for generated integer
upper
)

Generates a uniformly distributed random long integer between lower and upper (endpoints included) from a secure random sequence.

public double

Returns:

a uniformly distributed random value between lower and upper (exclusive)
nextUniform
(double
the exclusive lower bound of the support
lower
,
double
the exclusive upper bound of the support
upper
)

Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).

public double

Returns:

uniformly distributed random value in the (lower, upper) interval, if lowerInclusive is false, or in the [lower, upper) interval, if lowerInclusive is true
nextUniform
(double
the lower bound of the support
lower
,
double
the exclusive upper bound of the support
upper
,
boolean
true if the lower bound is inclusive
lowerInclusive
)

Generates a uniformly distributed random value from the interval (lower, upper) or the interval [lower, upper).

Method Detail

nextExponentialback to summary
public double nextExponential(double mean) throws NotStrictlyPositiveException

Generates a random value from the exponential distribution with specified mean.

Definition: Exponential Distribution

Parameters
mean:double

the mean of the distribution

Returns:double

a random value following the specified exponential distribution

Exceptions
NotStrictlyPositiveException:
if mean <= 0.
nextGaussianback to summary
public double nextGaussian(double mu, double sigma) throws NotStrictlyPositiveException

Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.

Definition: Normal Distribution

Parameters
mu:double

the mean of the distribution

sigma:double

the standard deviation of the distribution

Returns:double

a random value following the specified Gaussian distribution

Exceptions
NotStrictlyPositiveException:
if sigma <= 0.
nextHexStringback to summary
public String nextHexString(int len) throws NotStrictlyPositiveException

Generates a random string of hex characters of length len.

The generated string will be random, but not cryptographically secure. To generate cryptographically secure strings, use nextSecureHexString(int).

Parameters
len:int

the length of the string to be generated

Returns:String

a random string of hex characters of length len

Exceptions
NotStrictlyPositiveException:
if len <= 0
nextIntback to summary
public int nextInt(int lower, int upper) throws NumberIsTooLargeException

Generates a uniformly distributed random integer between lower and upper (endpoints included).

The generated integer will be random, but not cryptographically secure. To generate cryptographically secure integer sequences, use nextSecureInt(int, int).

Parameters
lower:int

lower bound for generated integer

upper:int

upper bound for generated integer

Returns:int

a random integer greater than or equal to lower and less than or equal to upper

Exceptions
NumberIsTooLargeException:
if lower >= upper
nextLongback to summary
public long nextLong(long lower, long upper) throws NumberIsTooLargeException

Generates a uniformly distributed random long integer between lower and upper (endpoints included).

The generated long integer values will be random, but not cryptographically secure. To generate cryptographically secure sequences of longs, use nextSecureLong(long, long).

Parameters
lower:long

lower bound for generated long integer

upper:long

upper bound for generated long integer

Returns:long

a random long integer greater than or equal to lower and less than or equal to upper

Exceptions
NumberIsTooLargeException:
if lower >= upper
nextPermutationback to summary
public int[] nextPermutation(int n, int k) throws NumberIsTooLargeException, NotStrictlyPositiveException

Generates an integer array of length k whose entries are selected randomly, without repetition, from the integers 0, ..., n - 1 (inclusive).

Generated arrays represent permutations of n taken k at a time.

Parameters
n:int

the domain of the permutation

k:int

the size of the permutation

Returns:int[]

a random k-permutation of n, as an array of integers

Exceptions
NumberIsTooLargeException:
if k > n.
NotStrictlyPositiveException:
if k <= 0.
nextPoissonback to summary
public long nextPoisson(double mean) throws NotStrictlyPositiveException

Generates a random value from the Poisson distribution with the given mean.

Definition: Poisson Distribution

Parameters
mean:double

the mean of the Poisson distribution

Returns:long

a random value following the specified Poisson distribution

Exceptions
NotStrictlyPositiveException:
if mean <= 0.
nextSampleback to summary
public Object[] nextSample(Collection<?> c, int k) throws NumberIsTooLargeException, NotStrictlyPositiveException

Returns an array of k objects selected randomly from the Collection c.

Sampling from c is without replacement; but if c contains identical objects, the sample may include repeats. If all elements of c are distinct, the resulting object array represents a Simple Random Sample of size k from the elements of c.

Parameters
c:Collection<?>

the collection to be sampled

k:int

the size of the sample

Returns:Object[]

a random sample of k elements from c

Exceptions
NumberIsTooLargeException:
if k > c.size().
NotStrictlyPositiveException:
if k <= 0.
nextSecureHexStringback to summary
public String nextSecureHexString(int len) throws NotStrictlyPositiveException

Generates a random string of hex characters from a secure random sequence.

If cryptographic security is not required, use nextHexString(int).

Parameters
len:int

the length of the string to be generated

Returns:String

a random string of hex characters of length len

Exceptions
NotStrictlyPositiveException:
if len <= 0
nextSecureIntback to summary
public int nextSecureInt(int lower, int upper) throws NumberIsTooLargeException

Generates a uniformly distributed random integer between lower and upper (endpoints included) from a secure random sequence.

Sequences of integers generated using this method will be cryptographically secure. If cryptographic security is not required, nextInt(int, int) should be used instead of this method.

Definition: Secure Random Sequence

Parameters
lower:int

lower bound for generated integer

upper:int

upper bound for generated integer

Returns:int

a random integer greater than or equal to lower and less than or equal to upper.

Exceptions
NumberIsTooLargeException:
if lower >= upper.
nextSecureLongback to summary
public long nextSecureLong(long lower, long upper) throws NumberIsTooLargeException

Generates a uniformly distributed random long integer between lower and upper (endpoints included) from a secure random sequence.

Sequences of long values generated using this method will be cryptographically secure. If cryptographic security is not required, nextLong(long, long) should be used instead of this method.

Definition: Secure Random Sequence

Parameters
lower:long

lower bound for generated integer

upper:long

upper bound for generated integer

Returns:long

a random long integer greater than or equal to lower and less than or equal to upper.

Exceptions
NumberIsTooLargeException:
if lower >= upper.
nextUniformback to summary
public double nextUniform(double lower, double upper) throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException

Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).

Definition: Uniform Distribution lower and upper - lower are the location and scale parameters, respectively.

Parameters
lower:double

the exclusive lower bound of the support

upper:double

the exclusive upper bound of the support

Returns:double

a uniformly distributed random value between lower and upper (exclusive)

Exceptions
NumberIsTooLargeException:
if lower >= upper
NotFiniteNumberException:
if one of the bounds is infinite
NotANumberException:
if one of the bounds is NaN
nextUniformback to summary
public double nextUniform(double lower, double upper, boolean lowerInclusive) throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException

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 lower and upper - lower are the location and scale parameters, respectively.

Parameters
lower:double

the lower bound of the support

upper:double

the exclusive upper bound of the support

lowerInclusive:boolean

true if the lower bound is inclusive

Returns:double

uniformly distributed random value in the (lower, upper) interval, if lowerInclusive is false, or in the [lower, upper) interval, if lowerInclusive is true

Exceptions
NumberIsTooLargeException:
if lower >= upper
NotFiniteNumberException:
if one of the bounds is infinite
NotANumberException:
if one of the bounds is NaN