public class RngStream extends java.lang.Object implements RandomNumberStream
RandomNumber
interface
for use in Simkit by Arnold Buss.Modifier and Type | Field and Description |
---|---|
static double |
a12 |
static double |
a13n |
private static double[][] |
A1p0 |
private static double[][] |
A1p127 |
private static double[][] |
A1p76 |
static double |
a21 |
static double |
a23n |
private static double[][] |
A2p0 |
private static double[][] |
A2p127 |
private static double[][] |
A2p76 |
private boolean |
anti |
private double[] |
Bg |
private double[] |
Cg |
private java.lang.String |
descriptor |
private int |
id |
private double[] |
Ig |
private static double[][] |
InvA1 |
private static double[][] |
InvA2 |
static double |
invtwo24 |
static double |
m1 |
static double |
m2 |
private static java.util.concurrent.atomic.AtomicInteger |
NEXT_ID |
private double[] |
nextSeed |
static double |
norm |
private boolean |
prec53 |
private int |
streamID |
private static double[] |
streamsOrigin |
private int |
substreamID |
static double |
two17 |
static double |
two53 |
Constructor and Description |
---|
RngStream()
Returns an independent instance of Stream[0:0], that is, a stream that
has no offsets from the system seeds
streamsOrigin . |
RngStream(int stream,
int substream)
Creates a new independent Stream[0:0] and advances it to the stream
and substream offsets given.
|
RngStream(java.lang.String name)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
advanceState(int e,
int c) |
private static int |
CheckSeed(long[] seed) |
double |
draw()
Draws a random number and returns it as U(0,1)
|
long |
drawLong()
Draws a random number and returns it as an integer.
|
double |
getMultiplier()
Returns the value for this RandomNumber needed to scale
a number produced by drawLong to result in U(0,1).
|
long |
getSeed()
Returns the current (not original) seed for this RandomNumber.
|
long[] |
getSeeds()
Gets the current (not original) value of the seeds for this RandomNumber.
|
double[] |
getState() |
int |
getStreamID() |
int |
getSubstreamID() |
void |
increasedPrecis(boolean incp) |
private static void |
matMatModM(double[][] A,
double[][] B,
double[][] C,
double m) |
private static void |
matPowModM(double[][] A,
double[][] B,
double m,
int c) |
private static void |
matTwoPowModM(double[][] A,
double[][] B,
double m,
int e) |
private static void |
matVecModM(double[][] A,
double[] s,
double[] v,
double m) |
private static double |
multModM(double a,
double s,
double c,
double m) |
int |
randInt(int i,
int j) |
double |
randU01() |
void |
resetNextStream()
Advances this instance to the next stream based on the current
stream baseline.
|
void |
resetNextSubstream()
advances generator to the next substream
|
void |
resetSeed()
Resets seed to last setSeed() value
|
void |
resetStartStream()
Reset the stream to its own individual starting point at substream 0.
|
void |
resetStartSubstream()
Reset the stream to its own individual starting point.
|
void |
setAntithetic(boolean a) |
static boolean |
setPackageSeed(long[] seed)
Set the system stream origin.
|
void |
setSeed(long arg0)
Set the random number seed for this RandomNumber.
|
boolean |
setSeed(long[] seed)
Position this stream at the indicated state.
|
void |
setSeeds(long[] seed)
Sets the seeds of this RandomNumber to the given values.
|
void |
setStreamAndSubstream(int stream,
int substream) |
java.lang.String |
toString() |
private double |
U01() |
private double |
U01d() |
void |
writeState() |
void |
writeStateFull() |
public static final double norm
public static final double m1
public static final double m2
public static final double a12
public static final double a13n
public static final double a21
public static final double a23n
public static final double two17
public static final double two53
public static final double invtwo24
private int streamID
private int substreamID
private static final double[][] InvA1
private static final double[][] InvA2
private static final double[][] A1p0
private static final double[][] A2p0
private static final double[][] A1p76
private static final double[][] A2p76
private static final double[][] A1p127
private static final double[][] A2p127
private static java.util.concurrent.atomic.AtomicInteger NEXT_ID
private static double[] streamsOrigin
private double[] nextSeed
private double[] Cg
private double[] Bg
private double[] Ig
private boolean anti
private boolean prec53
private java.lang.String descriptor
private int id
public RngStream()
streamsOrigin
. This is
Stream 0, Substream 0
Unlike the L'Ecuyer implementation, the default constructor in
simkit always returns the same stream. Like other places in
simkitk, streams instantiated in this way are not linked
but generate the same stream of random numbers. The seed
values that define this default stream are presently hard-coded
as they are in the L'Ecuyer implementation.
This changes the meaing of the instance variable id
to
one that is independent of the stream or substream the instance
represents, and, rather, simply gives a unique number to the
instance, which might be useful to client code or readers of
output.
The id concept has thus been replaced with values indicating which stream and substream offsets from the default this RngStream represents.
public RngStream(int stream, int substream)
stream
- given streamsubstream
- given substream@Deprecated public RngStream(java.lang.String name)
private static double multModM(double a, double s, double c, double m)
private static void matVecModM(double[][] A, double[] s, double[] v, double m)
private static void matMatModM(double[][] A, double[][] B, double[][] C, double m)
private static void matTwoPowModM(double[][] A, double[][] B, double m, int e)
private static void matPowModM(double[][] A, double[][] B, double m, int c)
private double U01()
private double U01d()
public void setStreamAndSubstream(int stream, int substream)
setStreamAndSubstream
in interface RandomNumberStream
public void resetNextStream()
public static boolean setPackageSeed(long[] seed)
seed
- Array of longs that will subsequently represent generator
state for Stream[0:0]public void resetStartStream()
Warning: this always implies the generator will be returned to Stream[x:0], even if it was instantiated at Stream[x:y]
public void resetStartSubstream()
public void resetNextSubstream()
public void setAntithetic(boolean a)
public void increasedPrecis(boolean incp)
public void advanceState(int e, int c)
private static int CheckSeed(long[] seed)
public boolean setSeed(long[] seed)
resetStartStream
or resetStartSubstream
is called.
The state of this generator loses any internal sense of its offset from the system Stream[0:0].
seed
- given seedpublic double[] getState()
public void writeState()
public void writeStateFull()
public double randU01()
public int randInt(int i, int j)
public void setSeed(long arg0)
RandomNumber
setSeed
in interface RandomNumber
arg0
- The new random number seedpublic long getSeed()
RandomNumber
getSeed
in interface RandomNumber
public void resetSeed()
RandomNumber
resetSeed
in interface RandomNumber
public void setSeeds(long[] seed)
RandomNumber
setSeeds
in interface RandomNumber
seed
- The new array of seedspublic long[] getSeeds()
RandomNumber
getSeeds
in interface RandomNumber
public double draw()
RandomNumber
draw
in interface RandomNumber
public long drawLong()
RandomNumber
drawLong
in interface RandomNumber
public double getMultiplier()
RandomNumber
getMultiplier
in interface RandomNumber
public java.lang.String toString()
toString
in class java.lang.Object
public int getStreamID()
getStreamID
in interface RandomNumberStream
public int getSubstreamID()
getSubstreamID
in interface RandomNumberStream