IRandom
public class RandomNumberGeneratorUnix extends java.lang.Object implements IRandom
Due to file access, this is likely to be slower than other RNG, but could be used to provide an initial seed.
Modifier and Type | Field | Description |
---|---|---|
protected byte[] |
buf |
|
protected java.io.FileInputStream |
fReader |
|
protected boolean |
hasNextGaussian |
|
protected double |
nextGaussian |
Constructor | Description |
---|---|
RandomNumberGeneratorUnix() |
Create an RNG using /dev/urandom as a source of random bits.
|
RandomNumberGeneratorUnix(java.lang.String randFile) |
Create an RNG using the given file as a source of random bits.
|
Modifier and Type | Method | Description |
---|---|---|
void |
dispose() |
Cleanup, close the file.
|
protected void |
fill(int offset,
int numBytes) |
Fills the byte buffer with random bytes up to numBytes, starting at
offset.
|
static int[] |
getRandSeedArray() |
Convenience method that returns an array of integers, useful as seeds to
another RNG.
|
static void |
main(java.lang.String[] args) |
|
double |
nextDouble() |
Returns a random double, uniformly distributed between 0 and 1.
|
double |
nextFixedDouble() |
Returns a pseudorandom double, uniformly distributed between
0.0 (inclusive) and 1.0 (exclusive).
|
float |
nextFloat() |
Returns a random float, uniformly distributed between 0 and 1.
|
double |
nextGaussian() |
Returns a double taken from a Gaussian distribution with 0 mean and
variance of 1.
|
int |
nextInt() |
Returns a random int (32-bit integer).
|
int |
nextInt(int max) |
Returns a random int ranging from 0 to max-1.
|
long |
nextLong() |
Returns a random long (64-bit integer).
|
long |
nextLong(long max) |
Returns a random long ranging from 0 to max-1.
|
protected final java.io.FileInputStream fReader
protected final byte[] buf
protected boolean hasNextGaussian
protected double nextGaussian
public RandomNumberGeneratorUnix()
public RandomNumberGeneratorUnix(java.lang.String randFile)
/dev/urandom as a randFile will not block /dev/random as a randFile may block if the entropy pool is depleted
public static int[] getRandSeedArray()
public static void main(java.lang.String[] args)
public void dispose()
protected void fill(int offset, int numBytes)
public long nextLong()
public int nextInt()
public int nextInt(int max)
public long nextLong(long max)
public float nextFloat()
public double nextDouble()
nextDouble
in interface IRandom
public double nextFixedDouble()
IRandom
nextFixedDouble
in interface IRandom
public double nextGaussian()
nextGaussian
in interface IRandom