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

public Class RandomDataImpl

extends Object
implements RandomData, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.random.RandomData
Annotations
@Deprecated
Imports
java.io.Serializable, java.security.NoSuchAlgorithmException, .NoSuchProviderException, java.util.Collection, org.apache.commons.math3.distribution.IntegerDistribution, .RealDistribution, org.apache.commons.math3.exception.NotANumberException, .NotFiniteNumberException, .NotPositiveException, .NotStrictlyPositiveException, .MathIllegalArgumentException, .NumberIsTooLargeException, .OutOfRangeException

Deprecated

to be removed in 4.0. Use RandomDataGenerator instead

Generates random deviates and other random data using a RandomGenerator instance to generate non-secure data and a java.security.SecureRandom instance to provide data for the nextSecureXxx methods. If no RandomGenerator is provided in the constructor, the default is to use a Well19937c generator. To plug in a different implementation, either implement RandomGenerator directly or extend AbstractRandomGenerator.

Supports reseeding the underlying pseudo-random number generator (PRNG). The SecurityProvider and Algorithm used by the SecureRandom instance can also be reset.

For details on the default PRNGs, see java.util.Random and java.security.SecureRandom.

Usage Notes:

Field Summary

Modifier and TypeField and Description
private final RandomDataGenerator
delegate

Deprecated as a consequence of RandomDataGenerator being deprecated.
RandomDataGenerator delegate
private static final long
serialVersionUID

Serializable version identifier

Constructor Summary

AccessConstructor and Description
public
RandomDataImpl()

Construct a RandomDataImpl, using a default random generator as the source of randomness.

public
RandomDataImpl(RandomGenerator
the source of (non-secure) random data (may be null, resulting in the default generator)
rand
)

Construct a RandomDataImpl using the supplied RandomGenerator as the source of (non-secure) random data.

Method Summary

Modifier and TypeMethod and Description
pack-priv RandomDataGenerator

Returns:

the delegate object.
getDelegate
()
Deprecated To be removed in 4.0.

public double

Returns:

random value sampled from the beta(alpha, beta) distribution
nextBeta
(double
first distribution shape parameter
alpha
,
double
second distribution shape parameter
beta
)

Generates a random value from the Beta Distribution.

public int

Returns:

random value sampled from the Binomial(numberOfTrials, probabilityOfSuccess) distribution
nextBinomial
(int
number of trials of the Binomial distribution
numberOfTrials
,
double
probability of success of the Binomial distribution
probabilityOfSuccess
)

Generates a random value from the Binomial Distribution.

public double

Returns:

random value sampled from the Cauchy(median, scale) distribution
nextCauchy
(double
the median of the Cauchy distribution
median
,
double
the scale parameter of the Cauchy distribution
scale
)

Generates a random value from the Cauchy Distribution.

public double

Returns:

random value sampled from the ChiSquare(df) distribution
nextChiSquare
(double
the degrees of freedom of the ChiSquare distribution
df
)

Generates a random value from the ChiSquare Distribution.

public double
nextExponential(double
the mean of the distribution
mean
)

Implements org.apache.commons.math3.random.RandomData.nextExponential.

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

public double

Returns:

random value sampled from the F(numeratorDf, denominatorDf) distribution
nextF
(double
the numerator degrees of freedom of the F distribution
numeratorDf
,
double
the denominator degrees of freedom of the F distribution
denominatorDf
)

Generates a random value from the F Distribution.

public double

Returns:

random value sampled from the Gamma(shape, scale) distribution
nextGamma
(double
the median of the Gamma distribution
shape
,
double
the scale parameter of the Gamma distribution
scale
)

Generates a random value from the Gamma Distribution.

public double
nextGaussian(double
the mean of the distribution
mu
,
double
the standard deviation of the distribution
sigma
)

Implements org.apache.commons.math3.random.RandomData.nextGaussian.

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

public String

Returns:

the random string.
nextHexString
(int
the desired string length.
len
)

Implements org.apache.commons.math3.random.RandomData.nextHexString.

Generates a random string of hex characters of length len.

public int

Returns:

random value sampled from the Hypergeometric(numberOfSuccesses, sampleSize) distribution
nextHypergeometric
(int
the population size of the Hypergeometric distribution
populationSize
,
int
number of successes in the population of the Hypergeometric distribution
numberOfSuccesses
,
int
the sample size of the Hypergeometric distribution
sampleSize
)

Generates a random value from the Hypergeometric Distribution.

public int
nextInt(int
lower bound for generated integer
lower
,
int
upper bound for generated integer
upper
)

Implements org.apache.commons.math3.random.RandomData.nextInt.

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

public double

Returns:

a random value sampled from the given distribution
nextInversionDeviate
(RealDistribution
Continuous distribution to generate a random value from
distribution
)
Deprecated use the distribution's sample() method

Generate a random deviate from the given distribution using the inversion method.

public int

Returns:

a random value sampled from the given distribution
nextInversionDeviate
(IntegerDistribution
Integer distribution to generate a random value from
distribution
)
Deprecated use the distribution's sample() method

Generate a random deviate from the given distribution using the inversion method.

public long
nextLong(long
lower bound for generated long integer
lower
,
long
upper bound for generated long integer
upper
)

Implements org.apache.commons.math3.random.RandomData.nextLong.

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

public int

Returns:

random value sampled from the Pascal(r, p) distribution
nextPascal
(int
the number of successes of the Pascal distribution
r
,
double
the probability of success of the Pascal distribution
p
)

Generates a random value from the Pascal Distribution.

public int[]
nextPermutation(int
the domain of the permutation
n
,
int
the size of the permutation
k
)

Implements org.apache.commons.math3.random.RandomData.nextPermutation.

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

public long
nextPoisson(double
the mean of the Poisson distribution
mean
)

Implements org.apache.commons.math3.random.RandomData.nextPoisson.

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

public Object[]
nextSample(Collection<?>
the collection to be sampled
c
,
int
the size of the sample
k
)

Implements org.apache.commons.math3.random.RandomData.nextSample.

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

public String
nextSecureHexString(int
the length of the string to be generated
len
)

Implements org.apache.commons.math3.random.RandomData.nextSecureHexString.

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

public int
nextSecureInt(int
lower bound for generated integer
lower
,
int
upper bound for generated integer
upper
)

Implements org.apache.commons.math3.random.RandomData.nextSecureInt.

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

public long
nextSecureLong(long
lower bound for generated integer
lower
,
long
upper bound for generated integer
upper
)

Implements org.apache.commons.math3.random.RandomData.nextSecureLong.

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

public double

Returns:

random value from the T(df) distribution
nextT
(double
the degrees of freedom of the T distribution
df
)

Generates a random value from the T Distribution.

public double
nextUniform(double
the exclusive lower bound of the support
lower
,
double
the exclusive upper bound of the support
upper
)

Implements org.apache.commons.math3.random.RandomData.nextUniform.

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

public double
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
)

Implements org.apache.commons.math3.random.RandomData.nextUniform.

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

public double

Returns:

random value sampled from the Weibull(shape, size) distribution
nextWeibull
(double
the shape parameter of the Weibull distribution
shape
,
double
the scale parameter of the Weibull distribution
scale
)

Generates a random value from the Weibull Distribution.

public int

Returns:

random value sampled from the Zipf(numberOfElements, exponent) distribution
nextZipf
(int
the number of elements of the ZipfDistribution
numberOfElements
,
double
the exponent of the ZipfDistribution
exponent
)

Generates a random value from the Zipf Distribution.

public void
reSeed(long
the seed value to use
seed
)

Reseeds the random number generator with the supplied seed.

public void
reSeed()

Reseeds the random number generator with System.currentTimeMillis() + System.identityHashCode(this)).

public void
reSeedSecure()

Reseeds the secure random number generator with the current time in milliseconds.

public void
reSeedSecure(long
the seed value to use
seed
)

Reseeds the secure random number generator with the supplied seed.

public void
setSecureAlgorithm(String
the name of the PRNG algorithm
algorithm
,
String
the name of the provider
provider
)

Sets the PRNG algorithm for the underlying SecureRandom instance using the Security Provider API.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final RandomDataGenerator delegate

Deprecated

as a consequence of RandomDataGenerator being deprecated. See corresponding docs for further information.

RandomDataGenerator delegate

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

Constructor Detail

RandomDataImplback to summary
public RandomDataImpl()

Construct a RandomDataImpl, using a default random generator as the source of randomness.

The default generator is a Well19937c seeded with System.currentTimeMillis() + System.identityHashCode(this)). The generator is initialized and seeded on first use.

RandomDataImplback to summary
public RandomDataImpl(RandomGenerator rand)

Construct a RandomDataImpl using the supplied RandomGenerator as the source of (non-secure) random data.

Parameters
rand:RandomGenerator

the source of (non-secure) random data (may be null, resulting in the default generator)

Since
1.1

Method Detail

getDelegateback to summary
pack-priv RandomDataGenerator getDelegate()

Deprecated

To be removed in 4.0.

Returns:RandomDataGenerator

the delegate object.

Annotations
@Deprecated
nextBetaback to summary
public double nextBeta(double alpha, double beta)

Generates a random value from the Beta Distribution. This implementation uses inversion to generate random values.

Parameters
alpha:double

first distribution shape parameter

beta:double

second distribution shape parameter

Returns:double

random value sampled from the beta(alpha, beta) distribution

Since
2.2
nextBinomialback to summary
public int nextBinomial(int numberOfTrials, double probabilityOfSuccess)

Generates a random value from the Binomial Distribution. This implementation uses inversion to generate random values.

Parameters
numberOfTrials:int

number of trials of the Binomial distribution

probabilityOfSuccess:double

probability of success of the Binomial distribution

Returns:int

random value sampled from the Binomial(numberOfTrials, probabilityOfSuccess) distribution

Since
2.2
nextCauchyback to summary
public double nextCauchy(double median, double scale)

Generates a random value from the Cauchy Distribution. This implementation uses inversion to generate random values.

Parameters
median:double

the median of the Cauchy distribution

scale:double

the scale parameter of the Cauchy distribution

Returns:double

random value sampled from the Cauchy(median, scale) distribution

Since
2.2
nextChiSquareback to summary
public double nextChiSquare(double df)

Generates a random value from the ChiSquare Distribution. This implementation uses inversion to generate random values.

Parameters
df:double

the degrees of freedom of the ChiSquare distribution

Returns:double

random value sampled from the ChiSquare(df) distribution

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

Implements org.apache.commons.math3.random.RandomData.nextExponential.

Doc from org.apache.commons.math3.random.RandomData.nextExponential.

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

Definition: Exponential Distribution

Algorithm Description: Uses the Algorithm SA (Ahrens) from p. 876 in: [1]: Ahrens, J. H. and Dieter, U. (1972). Computer methods for sampling from the exponential and normal distributions. Communications of the ACM, 15, 873-882.

Parameters
mean:double

the mean of the distribution

Returns:double

a random value following the specified exponential distribution

Exceptions
NotStrictlyPositiveException:
if mean <= 0.
nextFback to summary
public double nextF(double numeratorDf, double denominatorDf) throws NotStrictlyPositiveException

Generates a random value from the F Distribution. This implementation uses inversion to generate random values.

Parameters
numeratorDf:double

the numerator degrees of freedom of the F distribution

denominatorDf:double

the denominator degrees of freedom of the F distribution

Returns:double

random value sampled from the F(numeratorDf, denominatorDf) distribution

Exceptions
NotStrictlyPositiveException:
if numeratorDf <= 0 or denominatorDf <= 0.
Since
2.2
nextGammaback to summary
public double nextGamma(double shape, double scale) throws NotStrictlyPositiveException

Generates a random value from the Gamma Distribution.

This implementation uses the following algorithms:

For 0 < shape < 1:
Ahrens, J. H. and Dieter, U., Computer methods for sampling from gamma, beta, Poisson and binomial distributions. Computing, 12, 223-246, 1974.

For shape >= 1:
Marsaglia and Tsang, A Simple Method for Generating Gamma Variables. ACM Transactions on Mathematical Software, Volume 26 Issue 3, September, 2000.

Parameters
shape:double

the median of the Gamma distribution

scale:double

the scale parameter of the Gamma distribution

Returns:double

random value sampled from the Gamma(shape, scale) distribution

Exceptions
NotStrictlyPositiveException:
if shape <= 0 or scale <= 0.
Since
2.2
nextGaussianback to summary
public double nextGaussian(double mu, double sigma) throws NotStrictlyPositiveException

Implements org.apache.commons.math3.random.RandomData.nextGaussian.

Doc from org.apache.commons.math3.random.RandomData.nextGaussian.

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

Implements org.apache.commons.math3.random.RandomData.nextHexString.

Doc from org.apache.commons.math3.random.RandomData.nextHexString.

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).

Algorithm Description: hex strings are generated using a 2-step process.

  1. len / 2 + 1 binary bytes are generated using the underlying Random
  2. Each binary byte is translated into 2 hex digits

Parameters
len:int

the desired string length.

Returns:String

the random string.

Exceptions
NotStrictlyPositiveException:
if len <= 0.
nextHypergeometricback to summary
public int nextHypergeometric(int populationSize, int numberOfSuccesses, int sampleSize) throws NotPositiveException, NotStrictlyPositiveException, NumberIsTooLargeException

Generates a random value from the Hypergeometric Distribution. This implementation uses inversion to generate random values.

Parameters
populationSize:int

the population size of the Hypergeometric distribution

numberOfSuccesses:int

number of successes in the population of the Hypergeometric distribution

sampleSize:int

the sample size of the Hypergeometric distribution

Returns:int

random value sampled from the Hypergeometric(numberOfSuccesses, sampleSize) distribution

Exceptions
NotPositiveException:
if numberOfSuccesses < 0.
NotStrictlyPositiveException:
if populationSize <= 0.
NumberIsTooLargeException:
if numberOfSuccesses > populationSize, or sampleSize > populationSize.
Since
2.2
nextIntback to summary
public int nextInt(int lower, int upper) throws NumberIsTooLargeException

Implements org.apache.commons.math3.random.RandomData.nextInt.

Doc from org.apache.commons.math3.random.RandomData.nextInt.

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
nextInversionDeviateback to summary
public double nextInversionDeviate(RealDistribution distribution) throws MathIllegalArgumentException

Deprecated

use the distribution's sample() method

Generate a random deviate from the given distribution using the inversion method.

Parameters
distribution:RealDistribution

Continuous distribution to generate a random value from

Returns:double

a random value sampled from the given distribution

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if the underlynig distribution throws one
Since
2.2
nextInversionDeviateback to summary
public int nextInversionDeviate(IntegerDistribution distribution) throws MathIllegalArgumentException

Deprecated

use the distribution's sample() method

Generate a random deviate from the given distribution using the inversion method.

Parameters
distribution:IntegerDistribution

Integer distribution to generate a random value from

Returns:int

a random value sampled from the given distribution

Annotations
@Deprecated
Exceptions
MathIllegalArgumentException:
if the underlynig distribution throws one
Since
2.2
nextLongback to summary
public long nextLong(long lower, long upper) throws NumberIsTooLargeException

Implements org.apache.commons.math3.random.RandomData.nextLong.

Doc from org.apache.commons.math3.random.RandomData.nextLong.

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
nextPascalback to summary
public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException

Generates a random value from the Pascal Distribution. This implementation uses inversion to generate random values.

Parameters
r:int

the number of successes of the Pascal distribution

p:double

the probability of success of the Pascal distribution

Returns:int

random value sampled from the Pascal(r, p) distribution

Exceptions
NotStrictlyPositiveException:
if the number of successes is not positive
OutOfRangeException:
if the probability of success is not in the range [0, 1].
Since
2.2
nextPermutationback to summary
public int[] nextPermutation(int n, int k) throws NotStrictlyPositiveException, NumberIsTooLargeException

Implements org.apache.commons.math3.random.RandomData.nextPermutation.

Doc from org.apache.commons.math3.random.RandomData.nextPermutation.

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.

Uses a 2-cycle permutation shuffle. The shuffling process is described here.

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
NotStrictlyPositiveException:
if k <= 0.
NumberIsTooLargeException:
if k > n.
nextPoissonback to summary
public long nextPoisson(double mean) throws NotStrictlyPositiveException

Implements org.apache.commons.math3.random.RandomData.nextPoisson.

Doc from org.apache.commons.math3.random.RandomData.nextPoisson.

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

Definition: Poisson Distribution

Algorithm Description:

  • For small means, uses simulation of a Poisson process using Uniform deviates, as described here. The Poisson process (and hence value returned) is bounded by 1000 * mean.
  • For large means, uses the rejection algorithm described in
    Devroye, Luc. (1981).The Computer Generation of Poisson Random Variables Computing vol. 26 pp. 197-207.

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 NotStrictlyPositiveException, NumberIsTooLargeException

Implements org.apache.commons.math3.random.RandomData.nextSample.

Doc from org.apache.commons.math3.random.RandomData.nextSample.

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.

Algorithm Description: Uses a 2-cycle permutation shuffle to generate a random permutation of c.size() and then returns the elements whose indexes correspond to the elements of the generated permutation. This technique is described, and proven to generate random samples here

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
NotStrictlyPositiveException:
if k <= 0.
NumberIsTooLargeException:
if k > c.size().
nextSecureHexStringback to summary
public String nextSecureHexString(int len) throws NotStrictlyPositiveException

Implements org.apache.commons.math3.random.RandomData.nextSecureHexString.

Doc from org.apache.commons.math3.random.RandomData.nextSecureHexString.

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

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

Algorithm Description: hex strings are generated in 40-byte segments using a 3-step process.

  1. 20 random bytes are generated using the underlying SecureRandom.
  2. SHA-1 hash is applied to yield a 20-byte binary digest.
  3. Each byte of the binary digest is converted to 2 hex digits.

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

Implements org.apache.commons.math3.random.RandomData.nextSecureInt.

Doc from org.apache.commons.math3.random.RandomData.nextSecureInt.

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

Implements org.apache.commons.math3.random.RandomData.nextSecureLong.

Doc from org.apache.commons.math3.random.RandomData.nextSecureLong.

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.
nextTback to summary
public double nextT(double df) throws NotStrictlyPositiveException

Generates a random value from the T Distribution. This implementation uses inversion to generate random values.

Parameters
df:double

the degrees of freedom of the T distribution

Returns:double

random value from the T(df) distribution

Exceptions
NotStrictlyPositiveException:
if df <= 0
Since
2.2
nextUniformback to summary
public double nextUniform(double lower, double upper) throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException

Implements org.apache.commons.math3.random.RandomData.nextUniform.

Doc from org.apache.commons.math3.random.RandomData.nextUniform.

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.

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: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

Implements org.apache.commons.math3.random.RandomData.nextUniform.

Doc from org.apache.commons.math3.random.RandomData.nextUniform.

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.

Algorithm Description: if the lower bound is excluded, 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: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
Since
3.0
nextWeibullback to summary
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException

Generates a random value from the Weibull Distribution. This implementation uses inversion to generate random values.

Parameters
shape:double

the shape parameter of the Weibull distribution

scale:double

the scale parameter of the Weibull distribution

Returns:double

random value sampled from the Weibull(shape, size) distribution

Exceptions
NotStrictlyPositiveException:
if shape <= 0 or scale <= 0.
Since
2.2
nextZipfback to summary
public int nextZipf(int numberOfElements, double exponent) throws NotStrictlyPositiveException

Generates a random value from the Zipf Distribution. This implementation uses inversion to generate random values.

Parameters
numberOfElements:int

the number of elements of the ZipfDistribution

exponent:double

the exponent of the ZipfDistribution

Returns:int

random value sampled from the Zipf(numberOfElements, exponent) distribution

Exceptions
NotStrictlyPositiveException:
if numberOfElements <= 0 or exponent <= 0.
Since
2.2
reSeedback to summary
public void reSeed(long seed)

Reseeds the random number generator with the supplied seed.

Will create and initialize if null.

Parameters
seed:long

the seed value to use

reSeedback to summary
public void reSeed()

Reseeds the random number generator with System.currentTimeMillis() + System.identityHashCode(this)).

reSeedSecureback to summary
public void reSeedSecure()

Reseeds the secure random number generator with the current time in milliseconds.

Will create and initialize if null.

reSeedSecureback to summary
public void reSeedSecure(long seed)

Reseeds the secure random number generator with the supplied seed.

Will create and initialize if null.

Parameters
seed:long

the seed value to use

setSecureAlgorithmback to summary
public void setSecureAlgorithm(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException

Sets the PRNG algorithm for the underlying SecureRandom instance using the Security Provider API. The Security Provider API is defined in Java Cryptography Architecture API Specification & Reference.

USAGE NOTE: This method carries significant overhead and may take several seconds to execute.

Parameters
algorithm:String

the name of the PRNG algorithm

provider:String

the name of the provider

Exceptions
NoSuchAlgorithmException:
if the specified algorithm is not available
NoSuchProviderException:
if the specified provider is not installed