Interface RandomData
- All Known Implementing Classes:
RandomDataImpl
-
Method Summary
Modifier and TypeMethodDescriptiondoublenextExponential(double mean) Generates a random value from the exponential distribution with expected value =mean.doublenextGaussian(double mu, double sigma) Generates a random value from the Normal (or Gaussian) distribution with the given mean and standard deviation.nextHexString(int len) Generates a random string of hex characters of lengthlen.intnextInt(int lower, int upper) Generates a uniformly distributed random integer betweenlowerandupper(endpoints included).longnextLong(long lower, long upper) Generates a uniformly distributed random long integer betweenlowerandupper(endpoints included).int[]nextPermutation(int n, int k) Generates an integer array of lengthkwhose entries are selected randomly, without repetition, from the integers0 through n-1(inclusive).longnextPoisson(double mean) Generates a random value from the Poisson distribution with the given mean.Object[]nextSample(Collection<?> c, int k) Returns an array ofkobjects selected randomly from the Collectionc.nextSecureHexString(int len) Generates a random string of hex characters from a secure random sequence.intnextSecureInt(int lower, int upper) Generates a uniformly distributed random integer betweenlowerandupper(endpoints included) from a secure random sequence.longnextSecureLong(long lower, long upper) Generates a 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).
-
Method Details
-
nextHexString
Generates a random string of hex characters of lengthlen.The generated string will be random, but not cryptographically secure. To generate cryptographically secure strings, use
nextSecureHexStringPreconditions:
len > 0(otherwise an IllegalArgumentException is thrown.)
- Parameters:
len- the length of the string to be generated- Returns:
- random string of hex characters of length
len
-
nextInt
int nextInt(int lower, int upper) Generates a uniformly distributed random integer betweenlowerandupper(endpoints included).The generated integer will be random, but not cryptographically secure. To generate cryptographically secure integer sequences, use
nextSecureInt.Preconditions:
lower invalid input: '<' upper(otherwise an IllegalArgumentException is thrown.)
- Parameters:
lower- lower bound for generated integerupper- upper bound for generated integer- Returns:
- a random integer greater than or equal to
lowerand less than or equal toupper.
-
nextLong
long nextLong(long lower, long upper) Generates a uniformly distributed random long integer betweenlowerandupper(endpoints included).The generated long integer values will be random, but not cryptographically secure. To generate cryptographically secure sequences of longs, use
nextSecureLongPreconditions:
lower invalid input: '<' upper(otherwise an IllegalArgumentException is thrown.)
- Parameters:
lower- lower bound for generated integerupper- upper bound for generated integer- Returns:
- a random integer greater than or equal to
lowerand less than or equal toupper.
-
nextSecureHexString
Generates a random string of hex characters from a secure random sequence.If cryptographic security is not required, use
nextHexString().Preconditions:
len > 0(otherwise an IllegalArgumentException is thrown.)
- Parameters:
len- length of return string- Returns:
- the random hex string
-
nextSecureInt
int nextSecureInt(int lower, int upper) Generates a uniformly distributed random integer betweenlowerandupper(endpoints included) from a secure random sequence.Sequences of integers generated using this method will be cryptographically secure. If cryptographic security is not required,
nextIntshould be used instead of this method.Definition: Secure Random Sequence
Preconditions:
lower invalid input: '<' upper(otherwise an IllegalArgumentException is thrown.)
- Parameters:
lower- lower bound for generated integerupper- upper bound for generated integer- Returns:
- a random integer greater than or equal to
lowerand less than or equal toupper.
-
nextSecureLong
long nextSecureLong(long lower, long upper) Generates a random long integer betweenlowerandupper(endpoints included).Sequences of long values generated using this method will be cryptographically secure. If cryptographic security is not required,
nextLongshould be used instead of this method.Definition: Secure Random Sequence
Preconditions:
lower invalid input: '<' upper(otherwise an IllegalArgumentException is thrown.)
- Parameters:
lower- lower bound for generated integerupper- upper bound for generated integer- Returns:
- a long integer greater than or equal to
lowerand less than or equal toupper.
-
nextPoisson
long nextPoisson(double mean) Generates a random value from the Poisson distribution with the given mean.Definition: Poisson Distribution
Preconditions:
- The specified mean must be positive (otherwise an IllegalArgumentException is thrown.)
- Parameters:
mean- Mean of the distribution- Returns:
- poisson deviate with the specified mean
-
nextGaussian
double nextGaussian(double mu, double sigma) Generates a random value from the Normal (or Gaussian) distribution with the given mean and standard deviation.Definition: Normal Distribution
Preconditions:
sigma > 0(otherwise an IllegalArgumentException is thrown.)
- Parameters:
mu- Mean of the distributionsigma- Standard deviation of the distribution- Returns:
- random value from Gaussian distribution with mean = mu, standard deviation = sigma
-
nextExponential
double nextExponential(double mean) Generates a random value from the exponential distribution with expected value =mean.Definition: Exponential Distribution
Preconditions:
mu >= 0(otherwise an IllegalArgumentException is thrown.)
- Parameters:
mean- Mean of the distribution- Returns:
- random value from exponential distribution
-
nextUniform
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.Preconditions:
lower invalid input: '<' upper(otherwise an IllegalArgumentException is thrown.)
- Parameters:
lower- lower endpoint of the interval of supportupper- upper endpoint of the interval of support- Returns:
- uniformly distributed random value between lower and upper (exclusive)
-
nextPermutation
int[] nextPermutation(int n, int k) Generates an integer array of lengthkwhose entries are selected randomly, without repetition, from the integers0 through n-1(inclusive).Generated arrays represent permutations of
ntakenkat a time.Preconditions:
-
k invalid input: '<'= n -
n > 0
- Parameters:
n- domain of the permutationk- size of the permutation- Returns:
- random k-permutation of n
-
-
nextSample
Returns an array ofkobjects selected randomly from the Collectionc.Sampling from
cis without replacement; but ifccontains identical objects, the sample may include repeats. If all elements ofcare distinct, the resulting object array represents a Simple Random Sample of sizekfrom the elements ofc.Preconditions:
- k must be less than or equal to the size of c
- c must not be empty
- Parameters:
c- collection to be sampledk- size of the sample- Returns:
- random sample of k elements from c
-