Tiny Mersenne Twister
READ ME FIRST
There are two kinds of programs in this archive file. One
is TinyMT and another
is TinyMTDC. TinyMT is a pseudorandom number
generator, while TinyMTDC is a parameter-set generator for TinyMT.
TinyMT
TinyMT is a small-sized pseudorandom number generator, compared
with Mersenne Twister or WELL RNG. tinymt32 uses 16 bytes for
its internal state vector and 12 bytes for its parameters, and
tinymt64 uses 16 bytes for its internal state vector and 16 bytes
for its parameters.
Pseudorandom number sequences generated by TinyMT has a period
of 2127-1.
- There are two types of TinyMT: tinymt32 and tinymt64.
tinymt32 outputs 32-bit unsigned integers and single precision
floating point numbers. On the other hand, tinymt64
outputs 64-bit unsigned integers and double precision floating
point numbers.
- TinyMT is not designed for a particular hardware. It will run on
many types of hardware, because of its small size.
- TinyMT generates pseudorandom numbers using two functions:
a state transition function and an output function.
The state transition function is an F2-linear
function whose characteristic polynomial is irreducible of degree 127.
The output function is not F2-linear,
but almost F2-linear. The output function is composed
from several F2-linear functions, except for one
non F2-linear operation, namely an addition as integers
modulo 232 (or mod 264 for tinymt64) which
replaces an F2-vector addition.
-
TinyMT passes Bigcrush test suite of TESTU01, which is one of the
severest tests against pseudorandom number generators. To be precise,
we used 10 parameter sets of tinymt32, and used 10 seeds for
each parameters, so we tested total 100 sequences using Bigcrush
test suite. Some sequences fails one or two tests in the test
suite, but the test suite has 160 tests, even the true random
sequence will possibly fail in some tests. We checked the test
that TinyMT failed in (with parameter sets and seeds), and we
could not find a systematic deviation when seeds are changed.
Thus, we conclude that TinyMT passed the Bigcrush test suite.
-
There is a notion of the dimension of equidistribution to v-bit
accuracy (k(v)). High values of k(v) shows high-dimensional
uniformity up to the v-bit precision. In the case of TinyMT,
we can not compute these values because of the non-linearity
of the output function. Instead, we compute k(v)s for a
linearized output function, and search for parameters with
high values of k(v). They are close to the theoretical
upper bound (dimension of the internal space / v), but far
smaller than Mersenne Twister 19937. For example, k(32) for
tinymt32 is smaller than 4, while k(32) for Mersenne Twister 19937
is 623.
-
TinyMT is not designed to replace Mersenne Twister.
In some applications, namely, hardware implementation or highly
parallel environment, the large state size (19937 bits) of
Mersenne Twister may be an obstruction for implementation.
TinyMT is designed for such situation, with small state size
and good randomness for that size of internal state.
Requirement
TinyMT is written in C language, and it uses stdint.h and inttypes.h
of c99.
- gcc supports c99, use std=c99 option.
- Visual Studio C/C++ does not support c99, but you can get
stdint.h and inttypes.h for Visual Studio from
msinttypes
in Google code.
Compile and check
- cd tinymt
- make all
- Executable file check32 and check64 are made
- To check these programs:
check32 8f7011ee fc78ff1f 3793fdff > tmp32.txt
diff tmp32.txt check32.out.txt
check64 fa051f40 ffd0fff4 58d02ffeffbfffbc > tmp64.txt
diff tmp64.txt check64.out.txt
O.K. if diff does not show differences
TinyMTDC
TinyMTDC is a parameter generator for TinyMT.
A user specifies an ID and the number of sets of parameters to be
generated. TinyMTDC can generate more than 216 distinct set
of parameters (with ID embedded) to be used as parameters in TinyMT.
- There are two types of TinyMTDC: tinymt32dc creates
parameter sets for tinymt32, and tinymt64dc creates those
for tinymt64.
- TinyMTDC generates specified number of parameters for
each ID. Maximum number of parameters for each id will be
less than 228.
- The characteristic polynomials of TinyMT using parameter
set generated by TinyMTDC is different when ID used by
TinyMTDC is different.
Required Library
TinyMTDC is written in C++ language using template features.
Compile
- change directory to dc/src
- make all
- tinymt32dc, tinymt64dc and getid are created
Programs and usage
-
tinymt32dc [-v] [-c count] [-s seed_string] [-f outputfile] ID
tinymt64dc [-v] [-c count] [-s seed_string] [-f outputfile] ID
- These two programs create parameter sets for tinymt32 and tinymt64.
- argument (required)
- ID
- ID should be a decimal number such that
0 <= ID < 232
For different ID's, the
generated random number sequences are highly independent.
(Mathematically saying, the characteristic polynomials
of the recursion are co-prime to each other.)
- arguments (optional)
- -v
- Verbose mode for debug. Do not use this.
- -c count
- specify the number of sets of parameters to
generate. If omitted, outputs one set of parameters.
When TinyMTDC is called with -c, an internal
counter is updated and parameter set are outputted.
When ID or the internal counter is distinct, the
characteristic polynomial of the state transition
function is assured to be distinct. Namely, different
pairs (ID, internal counter) yields different
characteristic polynomials.
- -a
- parameter sets are outputted as many as possible.
if -a is specified -c is ignored.
- -s seq
- set the internal counter to be seq.
If omitted, its max value is set.
- -m max-defect
-
the defect at v-bit accuracy means the gap between the
theoretical upper bound and the realized k(v). The total
dimension defect is the sum of these values for v=1 to 32
(for tinymt32) and for v=1 to 64 (for tinymt64).
If its value is smaller, then the generator is closer to
the theoretical upper bound. This option set the max
allowable value of this total dimension defect.
Parameter sets whose total dimension defect is greater
than max-defect are discarded. If
omitted, no parameter sets are discarded. If 0 is specified,
parameter sets with no defect at any v-bit accuracy will be
outputted.
- -f filename
- specify output file name. If omitted, standard
output stream is used.
- getid -b 32|64 mat1 mat2
getid -b 32|64 -r id seq
-
This program calculates the ID and the internal counter from
parameter sets of TinyMTDC.
-b option is used to distinguish parameters for tinymt32
or tinymt64. If omitted -b 32 is assumed.
When -r is specified, conversely, the program calculates
the parameters mat1 and mat2 from the ID and the internal counter.
This program may be used to resume parameter-set generation: from
the last (mat1, mat2) generated by TinyMTDC, getid computes the
corresponding (ID, seq). Then TinyMTDC with -s option for the
value (seq-1) will resume the previous parameter-set generation,
as follows.
$ tail -1 tinymt32dc.0.20.txt
9443129baa73b98c7b097ab82c074d03,32,0,65980cb3,eb38facf,
cc3b75ff,59,0
$ ./getid 65980cb3 eb38facf
id:0(0x0)
seq:2147482983(0x7ffffd67)
$ ./tinymt32dc -s 2147482983 0
# charactristic, type, id, mat1, mat2, tmat, weight, delta
9443129baa73b98c7b097ab82c074d03,32,0,65980cb3,eb38facf,cc3b75ff,59,0
output format of TinyMTDC
output of TinyMTDC is Comma Separated Value.
Here we explain each column.
Column or Row | Description |
The first row |
# charactristic, type, id, mat1, mat2, tmat1, weight, delta
The first row is always the same as above.
Each column of the row shows title of columns of following rows. |
1st column: charactristic |
The first column shows the characteristic polynomial of
the state transition function. In TinyMT's case,
the characteristic polynomial is an irreducible polynomial
of degree 127, and its coefficients are 0 or 1.
The corresponding hexadecimal number to the coefficients of
the polynomial (by descending order, i.e. the constant term comes
as LSB) is shown. The first digit of the hexadecimal number
is greater than or equals to 8, because its degree is 127,
and the last hexadecimal number is odd, because irreducible
polynomial (over F2) has constant term 1.
|
2nd column: type |
The second column shows whether this parameter set is for
tinymt32 or tinymt64.
|
3rd column: id |
Third column is the ID specified by user, in command line.
|
4th column: mat1 |
The fourth column shows mat1 parameter
in the hexadecimal notation.
|
5th column: mat2 |
The fifth column shows mat2 parameter in
the hexadecimal notation.
The parameters mat1 and mat2 determine
the state transition function of the generator.
|
6th column: tmat |
The sixth column shows tmat parameter
in the hexadecimal notation.
The parameter tmat determines the output function
of the generator.
|
7th column: weight |
The seventh column shows Hamming weight of the characteristic
polynomial. A thumb-nail rule says that the weight value not far
from half of the degree of the characteristic polynomial is
preferable.
|
8th column: delta |
The eighth column shows the total dimension defect, which
measures the gap from the theoretical upper bounds on the
dimensions of equidistribution.
0 is the best. TinyMTDC selects the parameter
tmat for which delta is small.
|
LICENSE
Copyright (c) 2011 Mutsuo Saito, Makoto Matsumoto, Hiroshima
University and The University of Tokyo. 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.