jp.ac.hiroshima_u.sci.math.saito.tinymt
Class TinyMT64

java.lang.Object
  extended by org.apache.commons.math.random.AbstractRandomGenerator
      extended by jp.ac.hiroshima_u.sci.math.saito.tinymt.TinyMT64
All Implemented Interfaces:
org.apache.commons.math.random.RandomGenerator

public final class TinyMT64
extends org.apache.commons.math.random.AbstractRandomGenerator

TinyMT64 is a pseudo random number generator.

To get an instance, call getDefault(long).

This class is not synchronized, One way to use TinyMT64 in concurrent environment is to use an instance per a thread.

This class supports jump function. User can get an array of pseudo random number generators by calling getDefaultArray(int, long, long), or getDefaultArray(int, String, long).

This class supports discrete characteristic polynomial generators. User can get an array of pseudo random number generators whose characteristic polynomials are discrete by calling getTinyMTArray(int, long).

Author:
M. Saito
See Also:
TinyMT web page

Method Summary
static TinyMT64 getDefault()
          Factory method which returns the TinyMT with the first generated parameter of TinyMTDC.
static TinyMT64 getDefault(int[] seeds)
          get default TinyMT32 with seeding by array.
static TinyMT64 getDefault(long seed)
          Factory method which returns the TinyMT with the first generated parameter of TinyMTDC.
static TinyMT64 getDefault(java.lang.String seed)
          Factory method which returns the TinyMT with the first generated parameter of TinyMTDC.
static TinyMT64[] getDefaultArray(int count, long seed, long jump)
          make and return an array of TinyMT.
static TinyMT64[] getDefaultArray(int count, java.lang.String seed, long jump)
          Make and return an array of TinyMT.
 int getDelta()
          return Delta of TinyMT.
 int getId()
          return ID of TinyMT.
 TinyMT64[] getJumpedArray(int count, long jump)
          Make and return an array of TinyMT.
static TinyMT64[] getTinyMTArray(int count, long seed)
          Make and return an array of TinyMT.
 int getWeight()
          return Hamming weight of characteristic polynomial of TinyMT.
 double nextDouble()
          returns double r, 0 <= r < 1.0.
 float nextFloat()
          returns float r, 0 <= r < 1.0.
 int nextInt()
          returns 32-bit integer.
 long nextLong()
          returns 64-bit integer.
 void setSeed(int[] seeds)
          initialize internal state.
 void setSeed(long seed)
          initialize internal state.
 void setSeed(long[] seeds)
          Seeding by array of long.
 void setSeed(java.lang.String seed)
          seeding by string, This will be convenient.
 
Methods inherited from class org.apache.commons.math.random.AbstractRandomGenerator
clear, nextBoolean, nextBytes, nextGaussian, nextInt, setSeed
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

nextInt

public int nextInt()
returns 32-bit integer.

Specified by:
nextInt in interface org.apache.commons.math.random.RandomGenerator
Overrides:
nextInt in class org.apache.commons.math.random.AbstractRandomGenerator
Returns:
next int

nextLong

public long nextLong()
returns 64-bit integer.

Specified by:
nextLong in interface org.apache.commons.math.random.RandomGenerator
Overrides:
nextLong in class org.apache.commons.math.random.AbstractRandomGenerator
Returns:
next long

setSeed

public void setSeed(java.lang.String seed)
seeding by string, This will be convenient. This function does not compatible from other language implementation because coding of characters are different.

Parameters:
seed - seed of pseudo random numbers

setSeed

public void setSeed(long[] seeds)
Seeding by array of long. This seeding is compatible with other language implementation.

Parameters:
seeds - seeds of pseudo random numbers.

setSeed

public void setSeed(int[] seeds)
initialize internal state.

Specified by:
setSeed in interface org.apache.commons.math.random.RandomGenerator
Overrides:
setSeed in class org.apache.commons.math.random.AbstractRandomGenerator
Parameters:
seeds - seeds of randomness

setSeed

public void setSeed(long seed)
initialize internal state.

Specified by:
setSeed in interface org.apache.commons.math.random.RandomGenerator
Specified by:
setSeed in class org.apache.commons.math.random.AbstractRandomGenerator
Parameters:
seed - seeds of randomness

getDefault

public static TinyMT64 getDefault(java.lang.String seed)
Factory method which returns the TinyMT with the first generated parameter of TinyMTDC.

Parameters:
seed - seed of pseudo random numbers.
Returns:
TinyMT with the first parameter.

getDefault

public static TinyMT64 getDefault(long seed)
Factory method which returns the TinyMT with the first generated parameter of TinyMTDC.

Parameters:
seed - seed of pseudo random numbers.
Returns:
TinyMT with the first parameter.

getDefault

public static TinyMT64 getDefault(int[] seeds)
get default TinyMT32 with seeding by array.

Parameters:
seeds - seeds for initialization.
Returns:
random number generator TinyMT32

getDefault

public static TinyMT64 getDefault()
Factory method which returns the TinyMT with the first generated parameter of TinyMTDC. System.nanoTime() and Thread.getId() are used for seed.

Returns:
TinyMT with the first parameter.

getDefaultArray

public static TinyMT64[] getDefaultArray(int count,
                                         long seed,
                                         long jump)
make and return an array of TinyMT. Each element has the same characteristic polynomial with TinyMT gotten by getDefaultMT. Especially, the first element is just same as default TinyMT. The second element has the state of jump * 264 steps after the first element. In other word, the first element will generate the same sequence with the second element, after jump * 264 pseudo random number generation.

Parameters:
count - number of TinyMT to be created.
seed - seed of first element
jump - step is jump * 264
Returns:
array of TinyMT

getDefaultArray

public static TinyMT64[] getDefaultArray(int count,
                                         java.lang.String seed,
                                         long jump)
Make and return an array of TinyMT. Each element has the same characteristic polynomial with TinyMT gotten by getDefaultMT. Especially, the first element is just same as default TinyMT. The second element has the state of jump * 264 steps after the first element. In other word, the first element will generate the same sequence with the second element, after jump * 264 pseudo random number generation.

Parameters:
count - number of TinyMT to be created.
seed - seed of first element
jump - step is jump * 264
Returns:
array of TinyMT

getJumpedArray

public TinyMT64[] getJumpedArray(int count,
                                 long jump)
Make and return an array of TinyMT. Each element of the array has the same characteristic polynomial with this. Especially, the first element is just same as this. The second element has the state of jump * 264 steps after the first element. In other word, the first element will generate the same sequence with the second element, after jump * 264 pseudo random number generation.

Parameters:
count - number of arrays
jump - jump step
Returns:
jumped array of TinyMT64.

getTinyMTArray

public static TinyMT64[] getTinyMTArray(int count,
                                        long seed)
                                 throws java.io.IOException
Make and return an array of TinyMT. Each element of the array has discrete characteristic polynomial. This function does not return defaultTinyMT. User can call getJumpedArray(int, long) using each element and can get more TinyMTs.

Parameters:
count - number of TinyMT to be created.
seed - seed of each element
Returns:
array of TinyMT
Throws:
java.io.IOException - when can't read resource file.

nextDouble

public double nextDouble()
returns double r, 0 <= r < 1.0.

Specified by:
nextDouble in interface org.apache.commons.math.random.RandomGenerator
Specified by:
nextDouble in class org.apache.commons.math.random.AbstractRandomGenerator
Returns:
next double

nextFloat

public float nextFloat()
returns float r, 0 <= r < 1.0.

Specified by:
nextFloat in interface org.apache.commons.math.random.RandomGenerator
Overrides:
nextFloat in class org.apache.commons.math.random.AbstractRandomGenerator
Returns:
next float

getId

public int getId()
return ID of TinyMT. ID is not unique in TinyMT.

Returns:
ID

getDelta

public int getDelta()
return Delta of TinyMT.

Returns:
Delta

getWeight

public int getWeight()
return Hamming weight of characteristic polynomial of TinyMT.

Returns:
Hamming weight