SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.random
Class RNG

java.lang.Object
  extended by com.numericalmethod.suanshu.stats.random.RNG
All Implemented Interfaces:
RandomLongGenerator, RandomNumberGenerator

public class RNG
extends java.lang.Object
implements RandomLongGenerator

This is the global pseudo-random number generator for the SuanShu library. All built-in random number and distribution generators call this class.

The following code always return the same instance of the global pseudo-random number generator. No new instance is created.

 RandomNumberGenerator rng = new RNG();
 

Seeding this RNG seeds the whole library.


Constructor Summary
RNG()
           
 
Method Summary
 double nextDouble()
          Get a double between 0 and 1.
 long nextLong()
          Get the next random long.
static double random()
          Get a double between 0 and 1.
 void seed(long... seeds)
          Seed the global pseudo-random number generator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RNG

public RNG()
Method Detail

random

public static double random()
Get a double between 0 and 1.

Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.

Returns:
a pseudorandom double between 0 and 1

seed

public void seed(long... seeds)
Seed the global pseudo-random number generator.

Although seeds is a long array, we use only the first element, namely, seeds[0].

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

nextDouble

public double nextDouble()
Get a double between 0 and 1.

This is the same as calling

double u = RNG.random();

In other words, the following code gives a reference to the same global random number generator.

RandomNumberGenerator rng = new RNG();

Specified by:
nextDouble in interface RandomNumberGenerator
Returns:
a random double between 0 and 1

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

SuanShu, a Java numerical and statistical library

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