public abstract class RandomEngine extends DoubleFunction implements IntFunction
Most probability distributions are obtained by using a uniform pseudo-random number generation engine followed by a transformation to the desired distribution. Thus, subclasses of this class are at the core of computational statistics, simulations, Monte Carlo methods, etc.
Subclasses produce uniformly distributed int's and long's in the closed intervals [Integer.MIN_VALUE,Integer.MAX_VALUE] and [Long.MIN_VALUE,Long.MAX_VALUE], respectively, as well as float's and double's in the open unit intervals (0.0f,1.0f) and (0.0,1.0), respectively.
Subclasses need to override one single method only: nextInt(). All other methods generating different data types or ranges are usually layered upon nextInt(). long's are formed by concatenating two 32 bit int's. float's are formed by dividing the interval [0.0f,1.0f] into 232 sub intervals, then randomly choosing one subinterval. double's are formed by dividing the interval [0.0,1.0] into 264 sub intervals, then randomly choosing one subinterval.
Note that this implementation is not synchronized.
MersenneTwister
,
Random
Constructor and Description |
---|
RandomEngine() |
Modifier and Type | Method and Description |
---|---|
double |
apply(double dummy)
Equivalent to raw().
|
int |
apply(int dummy)
Equivalent to nextInt().
|
double |
nextDouble() |
float |
nextFloat() |
abstract int |
nextInt() |
long |
nextLong() |
double |
raw() |
isDensifying
public double apply(double dummy)
apply
in class DoubleFunction
dummy
- double for the argumentpublic int apply(int dummy)
apply
in interface IntFunction
dummy
- argument passed to the function.public double nextDouble()
(0.0,1.0)
(excluding
0.0 and 1.0).public float nextFloat()
(0.0f, 1.0f)
(excluding
0.0f and 1.0f).public abstract int nextInt()
public long nextLong()
public double raw()
(0.0, 1.0)
(excluding
0.0 and 1.0).Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.