Package cern.jet.random.engine
Class DRand
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.jet.random.engine.RandomEngine
-
- cern.jet.random.engine.DRand
-
- All Implemented Interfaces:
DoubleFunction
,IntFunction
,Serializable
,Cloneable
public class DRand extends RandomEngine
Quick medium quality uniform pseudo-random number generator. Produces uniformly distributedint
'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.The seed can be any integer satisfying
0 < 4*seed+1 < 232
. In other words, there must holdseed >= 0 && seed < 1073741823
.Quality: This generator follows the multiplicative congruential method of the form
-
z(i+1) = a * z(i) (mod m)
witha=663608941 (=0X278DDE6DL), m=232
. -
z(i)
assumes all different values0 < 4*seed+1 < m
during a full period of 230.
Performance: TO_DO
Implementation: TO_DO
Note that this implementation is not synchronized.
- Version:
- 1.0, 09/24/99
- Author:
- wolfgang.hoschek@cern.ch
- See Also:
MersenneTwister
,Random
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SEED
-
Constructor Summary
Constructors Constructor Description DRand()
Constructs and returns a random number generator with a default seed, which is a constant.DRand(int seed)
Constructs and returns a random number generator with the given seed.DRand(Date d)
Constructs and returns a random number generator seeded with the given date.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
).protected void
setSeed(int seed)
Sets the receiver's seed.-
Methods inherited from class cern.jet.random.engine.RandomEngine
apply, apply, makeDefault, nextDouble, nextFloat, nextLong, raw
-
Methods inherited from class cern.colt.PersistentObject
clone
-
-
-
-
Field Detail
-
DEFAULT_SEED
public static final int DEFAULT_SEED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DRand
public DRand()
Constructs and returns a random number generator with a default seed, which is a constant.
-
DRand
public DRand(int seed)
Constructs and returns a random number generator with the given seed.- Parameters:
seed
- should not be 0, in such a caseDRand.DEFAULT_SEED
is substituted.
-
DRand
public DRand(Date d)
Constructs and returns a random number generator seeded with the given date.- Parameters:
d
- typicallynew java.util.Date()
-
-
Method Detail
-
nextInt
public 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
).- Specified by:
nextInt
in classRandomEngine
-
setSeed
protected void setSeed(int seed)
Sets the receiver's seed. This method resets the receiver's entire internal state. The following condition must hold:seed >= 0 && seed < (232-1) / 4
.- Parameters:
seed
- if the above condition does not hold, a modified seed that meets the condition is silently substituted.
-
-