Deprecated
as a consequence of RandomData being deprecated. See corresponding docs for further information.
RandomData interface 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. and
java..
Usage Notes:
RandomGenerator and
SecureRandom instances used in data generation. Therefore, to
generate a random sequence of values or strings, you should use just
one RandomDataImpl instance repeatedly.RandomDataImpl is created, the underlying random
number generators are not initialized. If you do not
explicitly seed the default non-secure generator, it is seeded with the
current time in milliseconds plus the system identity hash code on first use.
The same holds for the secure generator. If you provide a RandomGenerator
to the constructor, however, this generator is not reseeded by the constructor
nor is it reseeded on first use.reSeed and reSeedSecure methods delegate to the
corresponding methods on the underlying RandomGenerator and
SecureRandom instances. Therefore, reSeed(long)
fully resets the initial state of the non-secure random number generator (so
that reseeding with a specific value always results in the same subsequent
random sequence); whereas reSeedSecure(long) does not
reinitialize the secure random number generator (so secure sequences started
with calls to reseedSecure(long) won't be identical).RandomGenerator
or SecureRandom instances are not protected by synchronization and
are not guaranteed to be thread-safe. Therefore, if an instance of this class
is concurrently utilized by multiple threads, it is the responsibility of
client code to synchronize access to seeding and data generation methods.
| Modifier and Type | Field and Description |
|---|---|
| private RandomGenerator | rand
underlying random number generator |
| private RandomGenerator | secRand
underlying secure random number generator |
| private static final long | serialVersionUID
Serializable version identifier |
| Access | Constructor and Description |
|---|---|
| public | RandomDataGenerator()
Construct a RandomDataGenerator, using a default random generator as the source of randomness. |
| public | RandomDataGenerator(RandomGenerator
the source of (non-secure) random data
(may be null, resulting in the default generator) rand)Construct a RandomDataGenerator using the supplied |
| Modifier and Type | Method and Description |
|---|---|
| public RandomGenerator | Returns: the Random used to generate random dataReturns the RandomGenerator used to generate non-secure random data. |
| private RandomGenerator | Returns: the SecureRandom used to generate secure random data, wrapped in aRandomGenerator.Returns the SecureRandom used to generate secure random data. |
| private void | initRan()
Sets the default generator to a |
| public double | Returns: random value sampled from the beta(alpha, beta) distributionfirst distribution shape parameter alpha, double second distribution shape parameter beta)Generates a random value from the |
| public int | Returns: random value sampled from the Binomial(numberOfTrials, probabilityOfSuccess) distributionnumber of trials of the Binomial distribution numberOfTrials, double probability of success of the Binomial distribution probabilityOfSuccess)Generates a random value from the |
| public double | Returns: random value sampled from the Cauchy(median, scale) distributionthe median of the Cauchy distribution median, double the scale parameter of the Cauchy distribution scale)Generates a random value from the |
| public double | Returns: random value sampled from the ChiSquare(df) distributionthe degrees of freedom of the ChiSquare distribution df)Generates a random value from the |
| public double | nextExponential(double
the mean of the distribution mean)Implements org. Generates a random value from the exponential distribution with specified mean. |
| public double | Returns: random value sampled from the F(numeratorDf, denominatorDf) distributionthe 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 |
| public double | Returns: random value sampled from the Gamma(shape, scale) distributionthe median of the Gamma distribution shape, double the scale parameter of the Gamma distribution scale)Generates a random value from the
|
| public double | nextGaussian(double
the mean of the distribution mu, double the standard deviation of the distribution sigma)Implements org. Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation. |
| public String | Returns: the random string.the desired string length. len)Implements org. Generates a random string of hex characters of length |
| public int | Returns: random value sampled from the Hypergeometric(numberOfSuccesses, sampleSize) distributionthe 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 |
| public int | nextInt(final int
lower bound for generated integer lower, final int upper bound for generated integer upper)Implements org. Generates a uniformly distributed random integer between |
| public long | nextLong(final long
lower bound for generated long integer lower, final long upper bound for generated long integer upper)Implements org. Generates a uniformly distributed random long integer between
|
| private static long | Returns: a pseudorandom, uniformly distributedlong
value between 0 (inclusive) and n (exclusive).random generator to use rng, final long the bound on the random number to be returned. Must be
positive. n)Returns a pseudorandom, uniformly distributed |
| public int | Returns: random value sampled from the Pascal(r, p) distributionthe number of successes of the Pascal distribution r, double the probability of success of the Pascal distribution p)Generates a random value from the |
| public int[] | nextPermutation(int
the domain of the permutation n, int the size of the permutation k)Implements org. Generates an integer array of length |
| public long | nextPoisson(double
the mean of the Poisson distribution mean)Implements org. 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. Returns an array of |
| public String | nextSecureHexString(int
the length of the string to be generated len)Implements org. Generates a random string of hex characters from a secure random sequence. |
| public int | nextSecureInt(final int
lower bound for generated integer lower, final int upper bound for generated integer upper)Implements org. Generates a uniformly distributed random integer between |
| public long | nextSecureLong(final long
lower bound for generated integer lower, final long upper bound for generated integer upper)Implements org. Generates a uniformly distributed random long integer between
|
| public double | Returns: random value from the T(df) distributionthe degrees of freedom of the T distribution df)Generates a random value from the |
| public double | nextUniform(double
the exclusive lower bound of the support lower, double the exclusive upper bound of the support upper)Implements org. Generates a uniformly distributed random value from the open interval
|
| 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 inclusiveImplements org. Generates a uniformly distributed random value from the interval
|
| public double | Returns: random value sampled from the Weibull(shape, size) distributionthe shape parameter of the Weibull distribution shape, double the scale parameter of the Weibull distribution scale)Generates a random value from the |
| public int | Returns: random value sampled from the Zipf(numberOfElements, exponent) distributionthe number of elements of the ZipfDistribution numberOfElements, double the exponent of the ZipfDistribution exponent)Generates a random value from the |
| public void | |
| public void | reSeed()
Reseeds the random number generator with
|
| public void | |
| 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. |
| rand | back to summary |
|---|---|
| private RandomGenerator rand underlying random number generator | |
| secRand | back to summary |
|---|---|
| private RandomGenerator secRand underlying secure random number generator | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serializable version identifier | |
| RandomDataGenerator | back to summary |
|---|---|
| public RandomDataGenerator() Construct a RandomDataGenerator, using a default random generator as the source of randomness. The default generator is a | |
| RandomDataGenerator | back to summary |
|---|---|
| public RandomDataGenerator(RandomGenerator rand) Construct a RandomDataGenerator using the supplied
| |
| getRandomGenerator | back to summary |
|---|---|
| public RandomGenerator getRandomGenerator() Returns the RandomGenerator used to generate non-secure random data.
Creates and initializes a default generator if null. Uses a
| |
| getSecRan | back to summary |
|---|---|
| private RandomGenerator getSecRan() Returns the SecureRandom used to generate secure random data.
Creates and initializes if null. Uses
| |
| initRan | back to summary |
|---|---|
| private void initRan() Sets the default generator to a | |
| nextBeta | back to summary |
|---|---|
| public double nextBeta(double alpha, double beta) Generates a random value from the
| |
| nextBinomial | back to summary |
|---|---|
| public int nextBinomial(int numberOfTrials, double probabilityOfSuccess) Generates a random value from the
| |
| nextCauchy | back to summary |
|---|---|
| public double nextCauchy(double median, double scale) Generates a random value from the
| |
| nextChiSquare | back to summary |
|---|---|
| public double nextChiSquare(double df) Generates a random value from the
| |
| nextExponential | back to summary |
|---|---|
| public double nextExponential(double mean) throws NotStrictlyPositiveException Implements org. Doc from org. 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.
| |
| nextF | back to summary |
|---|---|
| public double nextF(double numeratorDf, double denominatorDf) throws NotStrictlyPositiveException Generates a random value from the
| |
| nextGamma | back to summary |
|---|---|
| public double nextGamma(double shape, double scale) throws NotStrictlyPositiveException Generates a random value from the
This implementation uses the following algorithms: For 0 < shape < 1: For shape >= 1:
| |
| nextGaussian | back to summary |
|---|---|
| public double nextGaussian(double mu, double sigma) throws NotStrictlyPositiveException Implements org. Doc from org. Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation. Definition: Normal Distribution
| |
| nextHexString | back to summary |
|---|---|
| public String nextHexString(int len) throws NotStrictlyPositiveException Implements org. Doc from org. Generates a random string of hex characters of length
The generated string will be random, but not cryptographically
secure. To generate cryptographically secure strings, use
Algorithm Description: hex strings are generated using a 2-step process.
| |
| nextHypergeometric | back to summary |
|---|---|
| public int nextHypergeometric(int populationSize, int numberOfSuccesses, int sampleSize) throws NotPositiveException, NotStrictlyPositiveException, NumberIsTooLargeException Generates a random value from the
| |
| nextInt | back to summary |
|---|---|
| public int nextInt(final int lower, final int upper) throws NumberIsTooLargeException Implements org. Doc from org. Generates a uniformly distributed random integer between
The generated integer will be random, but not cryptographically secure.
To generate cryptographically secure integer sequences, use
| |
| nextLong | back to summary |
|---|---|
| public long nextLong(final long lower, final long upper) throws NumberIsTooLargeException Implements org. Doc from org. Generates a uniformly distributed random long integer between
The generated long integer values will be random, but not
cryptographically secure. To generate cryptographically secure sequences
of longs, use
| |
| nextLong | back to summary |
|---|---|
| private static long nextLong(final RandomGenerator rng, final long n) throws IllegalArgumentException Returns a pseudorandom, uniformly distributed
| |
| nextPascal | back to summary |
|---|---|
| public int nextPascal(int r, double p) throws NotStrictlyPositiveException, OutOfRangeException Generates a random value from the
| |
| nextPermutation | back to summary |
|---|---|
| public int[] nextPermutation(int n, int k) throws NumberIsTooLargeException, NotStrictlyPositiveException Implements org. Doc from org. Generates an integer array of length
Generated arrays represent permutations of MathArrays. in order to create a random shuffle of the set
of natural numbers { 0, 1, ..., n - 1 }.
| |
| nextPoisson | back to summary |
|---|---|
| public long nextPoisson(double mean) throws NotStrictlyPositiveException Implements org. Doc from org. Generates a random value from the Poisson distribution with the given mean. Definition: Poisson Distribution Algorithm Description:
| |
| nextSample | back to summary |
|---|---|
| public Object[] nextSample(Collection<?> c, int k) throws NumberIsTooLargeException, NotStrictlyPositiveException Implements org. Doc from org. Returns an array of
Sampling from nextPermutation(c.
in order to sample the collection.
| |
| nextSecureHexString | back to summary |
|---|---|
| public String nextSecureHexString(int len) throws NotStrictlyPositiveException Implements org. Doc from org. Generates a random string of hex characters from a secure random sequence.
If cryptographic security is not required, use
Algorithm Description: hex strings are generated in 40-byte segments using a 3-step process.
| |
| nextSecureInt | back to summary |
|---|---|
| public int nextSecureInt(final int lower, final int upper) throws NumberIsTooLargeException Implements org. Doc from org. Generates a uniformly distributed random integer between
Sequences of integers generated using this method will be
cryptographically secure. If cryptographic security is not required,
Definition: Secure Random Sequence
| |
| nextSecureLong | back to summary |
|---|---|
| public long nextSecureLong(final long lower, final long upper) throws NumberIsTooLargeException Implements org. Doc from org. Generates a uniformly distributed random long integer between
Sequences of long values generated using this method will be
cryptographically secure. If cryptographic security is not required,
Definition: Secure Random Sequence
| |
| nextT | back to summary |
|---|---|
| public double nextT(double df) throws NotStrictlyPositiveException Generates a random value from the
| |
| nextUniform | back to summary |
|---|---|
| public double nextUniform(double lower, double upper) throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException Implements org. Doc from org. Generates a uniformly distributed random value from the open interval
Definition:
Uniform Distribution 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).
| |
| nextUniform | back to summary |
|---|---|
| public double nextUniform(double lower, double upper, boolean lowerInclusive) throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException Implements org. Doc from org. Generates a uniformly distributed random value from the interval
Definition:
Uniform Distribution 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).
| |
| nextWeibull | back to summary |
|---|---|
| public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException Generates a random value from the
| |
| nextZipf | back to summary |
|---|---|
| public int nextZipf(int numberOfElements, double exponent) throws NotStrictlyPositiveException Generates a random value from the
| |
| reSeed | back to summary |
|---|---|
| public void reSeed(long seed) Reseeds the random number generator with the supplied seed. Will create and initialize if null.
| |
| reSeed | back to summary |
|---|---|
| public void reSeed() Reseeds the random number generator with
| |
| reSeedSecure | back to summary |
|---|---|
| public void reSeedSecure() Reseeds the secure random number generator with the current time in milliseconds. Will create and initialize if null. | |
| reSeedSecure | back to summary |
|---|---|
| public void reSeedSecure(long seed) Reseeds the secure random number generator with the supplied seed. Will create and initialize if null.
| |
| setSecureAlgorithm | back 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.
| |