public class SourceOfRandomness extends Object
generators so they
can produce random values for property parameters.| Constructor and Description |
|---|
SourceOfRandomness(Random delegate)
Makes a new source of randomness.
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
choose(Collection<T> items)
Gives a random element of the given collection.
|
<T> T |
choose(T[] items)
Gives a random element of the given array.
|
BigInteger |
nextBigInteger(int numberOfBits)
Gives a random
BigInteger representable by the given number
of bits. |
boolean |
nextBoolean() |
byte |
nextByte(byte min,
byte max)
Gives a random
byte value, uniformly distributed across the
interval [min, max]. |
void |
nextBytes(byte[] bytes) |
byte[] |
nextBytes(int count)
Gives an array of a given length containing random bytes.
|
char |
nextChar(char min,
char max)
Gives a random
char value, uniformly distributed across the
interval [min, max]. |
double |
nextDouble() |
double |
nextDouble(double min,
double max)
Gives a random
double value in the interval
[min, max). |
Duration |
nextDuration(Duration min,
Duration max)
Gives a random
Duration value, uniformly distributed across the
interval [min, max]. |
float |
nextFloat() |
float |
nextFloat(float min,
float max)
Gives a random
float value in the interval
[min, max). |
double |
nextGaussian() |
Instant |
nextInstant(Instant min,
Instant max)
Gives a random
Instant value, uniformly distributed across the
interval [min, max]. |
int |
nextInt() |
int |
nextInt(int n) |
int |
nextInt(int min,
int max)
Gives a random
int value, uniformly distributed across the
interval [min, max]. |
long |
nextLong() |
long |
nextLong(long min,
long max)
Gives a random
long value, uniformly distributed across the
interval [min, max]. |
short |
nextShort(short min,
short max)
Gives a random
short value, uniformly distributed across the
interval [min, max]. |
long |
seed() |
void |
setSeed(long seed) |
Random |
toJDKRandom()
Gives a JDK source of randomness, with the same internal state as
this source of randomness.
|
public SourceOfRandomness(Random delegate)
delegate - a JDK source of randomness, to which the new instance
will delegatepublic Random toJDKRandom()
Gives a JDK source of randomness, with the same internal state as this source of randomness.
public boolean nextBoolean()
Random.nextBoolean()public void nextBytes(byte[] bytes)
bytes - a byte array to fill with random valuesRandom.nextBytes(byte[])public byte[] nextBytes(int count)
count - the desired length of the random byte arrayRandom.nextBytes(byte[])public double nextDouble()
double value in the
interval [0.0, 1.0)Random.nextDouble()public float nextFloat()
float value in the
interval [0.0, 1.0)Random.nextFloat()public double nextGaussian()
Random.nextGaussian()public int nextInt()
int valueRandom.nextInt()public int nextInt(int n)
n - upper boundint value in the interval
[0, n)Random.nextInt(int)public long nextLong()
long valueRandom.nextLong()public void setSeed(long seed)
seed - value with which to seed this source of randomnessRandom.setSeed(long)public long seed()
public byte nextByte(byte min,
byte max)
byte value, uniformly distributed across the
interval [min, max].min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic char nextChar(char min,
char max)
char value, uniformly distributed across the
interval [min, max].min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic double nextDouble(double min,
double max)
Gives a random double value in the interval
[min, max).
This naive implementation takes a random double value from
Random.nextDouble() and scales/shifts the value into the desired
interval. This may give surprising results for large ranges.
min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic float nextFloat(float min,
float max)
Gives a random float value in the interval
[min, max).
This naive implementation takes a random float value from
Random.nextFloat() and scales/shifts the value into the desired
interval. This may give surprising results for large ranges.
min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic int nextInt(int min,
int max)
int value, uniformly distributed across the
interval [min, max].min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic long nextLong(long min,
long max)
long value, uniformly distributed across the
interval [min, max].min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic short nextShort(short min,
short max)
short value, uniformly distributed across the
interval [min, max].min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic BigInteger nextBigInteger(int numberOfBits)
BigInteger representable by the given number
of bits.numberOfBits - the desired number of bitsBigIntegerBigInteger.BigInteger(int, java.util.Random)public Instant nextInstant(Instant min, Instant max)
Instant value, uniformly distributed across the
interval [min, max].min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic Duration nextDuration(Duration min, Duration max)
Duration value, uniformly distributed across the
interval [min, max].min - lower bound of the desired intervalmax - upper bound of the desired intervalpublic <T> T choose(Collection<T> items)
T - type of items in the collectionitems - a collectionpublic <T> T choose(T[] items)
T - type of items in the arrayitems - an array© Copyright 2010-2016 Paul R. Holser, Jr. All rights reserved. Licensed under The MIT License. pholser@alumni.rice.edu