SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.random.pseudorandom.linear
Class MRG

java.lang.Object
  extended by com.numericalmethod.suanshu.stats.random.pseudorandom.linear.MRG
All Implemented Interfaces:
LinearCongruentialGenerator, RandomLongGenerator, RandomNumberGenerator

public class MRG
extends java.lang.Object
implements LinearCongruentialGenerator

A Multiple Recursive Generator is a linear congruential generator which takes this form:

 xi = (a1 * xi-1 + a2 * xi-2 + ... + ak * xi-k) mod m
 ui = xi / m
 

See Also:
"p. 44. Monte Carlo Methods in Financial Engineering. Paul Glasserman. 2004."

Field Summary
 long m
          the modulus
 
Constructor Summary
MRG(long m, long... a)
          Construct a Multiple Recursive Generator.
 
Method Summary
 long modulus()
          Get the modulus of this linear congruential generator.
 double nextDouble()
          Get the next random double between 0 and 1.
 long nextLong()
          Get the next random long.
 int order()
          Get the order of recursion.
 void seed(long... x)
          This function must be called at least once before call nextLong() to seed the generator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m

public final long m
the modulus

Constructor Detail

MRG

public MRG(long m,
           long... a)
Construct a Multiple Recursive Generator.

Parameters:
m - the modulus
a - multipliers for the Lehmer rng (a long)
Method Detail

seed

public void seed(long... x)
This function must be called at least once before call nextLong() to seed the generator.

Specified by:
seed in interface RandomNumberGenerator
Parameters:
x - the seeds

order

public int order()
Description copied from interface: LinearCongruentialGenerator
Get the order of recursion.

Specified by:
order in interface LinearCongruentialGenerator
Returns:
the order of recursion

modulus

public long modulus()
Description copied from interface: LinearCongruentialGenerator
Get the modulus of this linear congruential generator.

Specified by:
modulus in interface LinearCongruentialGenerator
Returns:
m

nextLong

public long nextLong()
Description copied from interface: RandomLongGenerator
Get the next random long.

Specified by:
nextLong in interface RandomLongGenerator
Returns:
the next random long

nextDouble

public double nextDouble()
Get the next random double between 0 and 1.

Specified by:
nextDouble in interface RandomNumberGenerator
Returns:
the next random number between 0 and 1

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.