public class SobolQRNG extends java.lang.Object implements RandomnessSource
A Sobol sequence is a low-discrepancy sequence with the property that for all values of N, its subsequence (x1, ... xN) has a low discrepancy. It can be used to generate quasi-random points in a space S, which are equi-distributed. This is not a true random number generator, and is not even a pseudo-random number generator; the sequence generated from identical starting points with identical dimensions will be exactly the same. Calling this class' nextVector, nextIntVector, and nextLongVector methods all increment the position in the sequence, and do not use separate sequences for separate types.
The implementation already comes with support for up to 16 dimensions with direction numbers calculated from Stephen Joe and Frances Kuo.
The generator supports two modes:
nextVector()
, nextIntVector()
,
nextLongVector()
, and the bounded variants on each of thoseskipTo(int)
Constructor and Description |
---|
SobolQRNG(int dimension)
Construct a new Sobol sequence generator for the given space dimension.
|
Modifier and Type | Method and Description |
---|---|
SobolQRNG |
copy()
Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the
copy, both will generate the same sequence of random numbers from the point copy() was called.
|
boolean |
equals(java.lang.Object o) |
double[] |
fillVector(double[] toFill)
Generate a random vector.
|
int |
getNextIndex()
Returns the index i of the next point in the Sobol sequence that will be returned
by calling
nextVector() . |
int |
hashCode() |
int |
next(int bits)
Using this method, any algorithm that might use the built-in Java Random
can interface with this randomness source.
|
Coord |
nextCoord(int xLimit,
int yLimit)
Generate a random vector as a Coord, scaled between 0 (inclusive) and the given limits (exclusive).
|
double |
nextDouble() |
double |
nextDouble(double max) |
int[] |
nextIntVector()
Generate a random vector.
|
int[] |
nextIntVector(int max)
Generate a random vector.
|
long |
nextLong()
Using this method, any algorithm that needs to efficiently generate more
than 32 bits of random data can interface with this randomness source.
|
long[] |
nextLongVector()
Generate a random vector.
|
long[] |
nextLongVector(long max)
Generate a random vector.
|
double[] |
nextVector()
Generate a random vector.
|
double[] |
nextVector(double max)
Generate a random vector.
|
double[] |
skipTo(int index)
Skip to the i-th point in the Sobol sequence.
|
java.lang.String |
toString() |
public SobolQRNG(int dimension) throws java.lang.ArithmeticException
skipTo(int)
with a fairly large number (over 1000) to ensure the results aren't
too obviously non-random. If you skipTo(1), all doubles in that result will be 0.5, and if you skipTo(0),
all will be 0 (this class starts at index 1 instead of 0 for that reason). This is true for all dimensions.dimension
- the space dimensionjava.lang.ArithmeticException
- if the space dimension is outside the allowed range of [1, 16]public double[] nextVector()
public double[] fillVector(double[] toFill)
public Coord nextCoord(int xLimit, int yLimit)
xLimit
- the upper exclusive bound for the Coord's x-coordinateyLimit
- the upper exclusive bound for the Coord's y-coordinatepublic double[] nextVector(double max)
max
- the maximum exclusive value for the elements of the desired vector; minimum is 0 inclusive.public long[] nextLongVector()
public long[] nextLongVector(long max)
max
- the maximum exclusive value for the elements of the desired vector; minimum is 0 inclusive.public int[] nextIntVector()
public int[] nextIntVector(int max)
max
- the maximum exclusive value for the elements of the desired vector; minimum is 0 inclusive.public double[] skipTo(int index)
This operation can be performed in O(1). If index is somehow negative, this uses its absolute value instead of throwing an exception. If index is 0, the result will always be entirely 0. You should skipTo a number greater than 1000 if you want random-seeming individual numbers in each vector.
index
- the index in the sequence to skip topublic int getNextIndex()
nextVector()
.public int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic long nextLong()
nextLong
in interface RandomnessSource
public double nextDouble()
public double nextDouble(double max)
public SobolQRNG copy()
copy
in interface RandomnessSource
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.