public class SFMT19937 extends Object
The license (a modified BSD License) for the original C code from which this code is adapted:
Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
University. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the Hiroshima University nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ceroxylon at hotmail.com)| Modifier and Type | Field and Description |
|---|---|
(package private) int |
idx
Index counter of the next
int to return from next(). |
static int |
MEXP
Mersenne Exponent.
|
(package private) static int |
MSK1
A bitmask parameter, used in the recursion to break symmetry of SIMD.
|
(package private) static int |
MSK2
A bitmask parameter, used in the recursion to break symmetry of SIMD.
|
(package private) static int |
MSK3
A bitmask parameter, used in the recursion to break symmetry of SIMD.
|
(package private) static int |
MSK4
A bitmask parameter, used in the recursion to break symmetry of SIMD.
|
(package private) static int |
N
The SFMT generator has an internal state array of 128-bit integers, and
N is its size. |
static int |
N32
N32 is the size of internal state array when regarded as an
array of 32-bit integers. |
(package private) static int[] |
parity
A parity check vector which certifies the period of 2
MEXP
. |
(package private) static int |
PARITY1
Part of a 128-bit period certification vector.
|
(package private) static int |
PARITY2
Part of a 128-bit period certification vector.
|
(package private) static int |
PARITY3
Part of a 128-bit period certification vector.
|
(package private) static int |
PARITY4
Part of a 128-bit period certification vector.
|
(package private) static int |
POS1
The pick up position of the array.
|
(package private) int[] |
sfmt
The internal state array.
|
(package private) static int |
SL1
The parameter of shift left as four 32-bit registers.
|
(package private) static int |
SL2
The parameter of shift left as one 128-bit register.
|
(package private) static int |
SR1
The parameter of shift right as four 32-bit registers.
|
(package private) static int |
SR2
The parameter of shift right as one 128-bit register.
|
(package private) static long |
uniquifier
A number mixed with the time of day to provide a unique seed to each
generator of this type allocated.
|
| Constructor and Description |
|---|
SFMT19937()
Constructor that initially uses a seed based on the time of day.
|
SFMT19937(long seed)
Constructor that initializes the internal state array by calling
setSeed(long) with the specified argument. |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
doRecursion(int[] r,
int rI,
int[] a,
int aI,
int[] b,
int bI,
int[] c,
int cI,
int[] d,
int dI)
Applies the recursion formula.
|
void |
fillArray(int[] array)
Fills the given array with pseudorandom 32-bit integers.
|
void |
fillArray(int[] array,
int elems)
Fills the given array with the specified number of pseudorandom 32-bit
integers.
|
(package private) int |
func1(int x)
Used by
initByArray(int...). |
(package private) int |
func2(int x)
Used by
initByArray(int...). |
(package private) void |
genRandAll()
Fills the internal state array with pseudorandom integers.
|
(package private) void |
genRandArray(int[] array,
int size)
Fills a user-specified array with pseudorandom integers.
|
void |
initByArray(int... key)
Initializes the internal state array with an array of 32-bit integers.
|
int |
minArraySize()
Returns the smallest array size allowed as an argument to
fillArray(int[]). |
int |
next()
Generates and returns the next 32-bit pseudorandom number.
|
(package private) void |
periodCertification()
Certifies the period of 2
MEXP. |
void |
setIntSeed(int seed)
Initializes the internal state array with a 32-bit seed.
|
void |
setSeed(long seed)
Initializes the internal state array with a 64-bit seed.
|
public static final int MEXP
MEXP − 1. If you adapt this code to support a
different exponent, you must change many of the other constants here as
well; consult the original C code.static final int N
N is its size.public static final int N32
N32 is the size of internal state array when regarded as an
array of 32-bit integers.static final int POS1
static final int SL1
static final int SL2
SL2 * 8 bits.static final int SR1
static final int SR2
SL2 * 8 bits.static final int MSK1
static final int MSK2
static final int MSK3
static final int MSK4
static final int PARITY1
static final int PARITY2
static final int PARITY3
static final int PARITY4
static final int[] parity
MEXP
.static long uniquifier
final int[] sfmt
ints
are often treated as a single 128-bit integer that is
little-endian—that is, its low-order bits are at lower indices in
the array, and high-order bits at higher indices.int idx
int to return from next().public SFMT19937()
public SFMT19937(long seed)
setSeed(long) with the specified argument.seed - initial seed for this generator.void doRecursion(int[] r,
int rI,
int[] a,
int aI,
int[] b,
int bI,
int[] c,
int cI,
int[] d,
int dI)
r - output array.rI - index in r.a - state array.aI - index in a.b - state array.bI - index in b.c - state array.cI - index in c.d - state array.dI - index in d.void genRandAll()
void genRandArray(int[] array,
int size)
array - 128-bit array to be filled with pseudorandom numbers.size - number of elements of array to fill.IllegalArgumentException - if size is greater than the length of
array, or if size is less than
N32, or is not a multiple of 4.int func1(int x)
initByArray(int...).x - 32-bit integer.int func2(int x)
initByArray(int...).x - 32-bit integer.void periodCertification()
MEXP.public int minArraySize()
fillArray(int[]).public int next()
public void fillArray(int[] array)
fillArray(int[],int) applied to
(array,array.length).array - array to fill.public void fillArray(int[] array,
int elems)
array - array to fill.elems - the number of elements of array (starting at
index zero) to fill; subsequent elements are not modified.IllegalArgumentException - if elems is greater than the length of
array, or is less than N32, or is not a
multiple of 4.public void setIntSeed(int seed)
seed - 32-bit seed.public void setSeed(long seed)
seed - 64-bit seed.public void initByArray(int... key)
key - array of 32-bit integers, used as a seed.Copyright © 2018. All rights reserved.