Class RandomEngine
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.jet.random.engine.RandomEngine
-
- All Implemented Interfaces:
DoubleFunction
,IntFunction
,Serializable
,Cloneable
- Direct Known Subclasses:
DRand
,MersenneTwister
public abstract class RandomEngine extends PersistentObject implements DoubleFunction, IntFunction
Abstract base class for uniform pseudo-random number generating engines.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 andlong
's in the closed intervals[Integer.MIN_VALUE,Integer.MAX_VALUE]
and[Long.MIN_VALUE,Long.MAX_VALUE]
, respectively, as well asfloat
's anddouble
'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 uponnextInt()
.long
's are formed by concatenating two 32 bitint
'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.
- Version:
- 1.0, 09/24/99
- Author:
- wolfgang.hoschek@cern.ch
- See Also:
MersenneTwister
,Random
, Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RandomEngine()
Makes this class non instantiable, but still let's others inherit from it.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description double
apply(double dummy)
Equivalent toraw()
.int
apply(int dummy)
Equivalent tonextInt()
.static RandomEngine
makeDefault()
Constructs and returns a new uniform random number engine seeded with the current time.double
nextDouble()
Returns a 64 bit uniformly distributed random number in the open unit interval(0.0,1.0)
(excluding 0.0 and 1.0).float
nextFloat()
Returns a 32 bit uniformly distributed random number in the open unit interval(0.0f,1.0f)
(excluding 0.0f and 1.0f).abstract int
nextInt()
Returns a 32 bit uniformly distributed random number in the closed interval[Integer.MIN_VALUE,Integer.MAX_VALUE]
(includingInteger.MIN_VALUE
andInteger.MAX_VALUE
);long
nextLong()
Returns a 64 bit uniformly distributed random number in the closed interval[Long.MIN_VALUE,Long.MAX_VALUE]
(includingLong.MIN_VALUE
andLong.MAX_VALUE
).double
raw()
Returns a 32 bit uniformly distributed random number in the open unit interval(0.0,1.0)
(excluding 0.0 and 1.0).-
Methods inherited from class cern.colt.PersistentObject
clone
-
-
-
-
Method Detail
-
apply
public double apply(double dummy)
Equivalent toraw()
. This has the effect that random engines can now be used as function objects, returning a random number upon function evaluation.- Specified by:
apply
in interfaceDoubleFunction
- Parameters:
dummy
- argument passed to the function.- Returns:
- the result of the function.
-
apply
public int apply(int dummy)
Equivalent tonextInt()
. This has the effect that random engines can now be used as function objects, returning a random number upon function evaluation.- Specified by:
apply
in interfaceIntFunction
- Parameters:
dummy
- argument passed to the function.- Returns:
- the result of the function.
-
makeDefault
public static RandomEngine makeDefault()
Constructs and returns a new uniform random number engine seeded with the current time. Currently this isMersenneTwister
.
-
nextDouble
public double nextDouble()
Returns a 64 bit uniformly distributed random number in the open unit interval(0.0,1.0)
(excluding 0.0 and 1.0).
-
nextFloat
public float nextFloat()
Returns a 32 bit uniformly distributed random number in the open unit interval(0.0f,1.0f)
(excluding 0.0f and 1.0f).
-
nextInt
public abstract int nextInt()
Returns a 32 bit uniformly distributed random number in the closed interval[Integer.MIN_VALUE,Integer.MAX_VALUE]
(includingInteger.MIN_VALUE
andInteger.MAX_VALUE
);
-
nextLong
public long nextLong()
Returns a 64 bit uniformly distributed random number in the closed interval[Long.MIN_VALUE,Long.MAX_VALUE]
(includingLong.MIN_VALUE
andLong.MAX_VALUE
).
-
raw
public double raw()
Returns a 32 bit uniformly distributed random number in the open unit interval(0.0,1.0)
(excluding 0.0 and 1.0).
-
-