TinyMT32 Pseudorandom Number Generator (PRNG)Hiroshima UniversityJapansaito@math.sci.hiroshima-u.ac.jpHiroshima UniversityJapanm-mat@math.sci.hiroshima-u.ac.jpINRIAUniv. Grenoble AlpesFrancevincent.roca@inria.frINRIAFranceemmanuel.baccelli@inria.frTSVWG
This document describes the TinyMT32 Pseudorandom Number Generator (PRNG), which produces 32-bit pseudorandom unsigned integers and aims at having a simple-to-use and deterministic solution.
This PRNG is a small-sized variant of the Mersenne Twister (MT) PRNG.
The main advantage of TinyMT32 over MT is the use of a small internal state, compatible with most target platforms that include embedded devices, while keeping reasonably good randomness that represents a significant improvement compared to the Park-Miller Linear Congruential PRNG.
However, neither the TinyMT nor MT PRNG is meant to be used for cryptographic applications.
Status of This Memo
This is an Internet Standards Track document.
This document is a product of the Internet Engineering Task Force
(IETF). It represents the consensus of the IETF community. It has
received public review and has been approved for publication by
the Internet Engineering Steering Group (IESG). Further
information on Internet Standards is available in Section 2 of
RFC 7841.
Information about the current status of this document, any
errata, and how to provide feedback on it may be obtained at
.
Copyright Notice
Copyright (c) 2020 IETF Trust and the persons identified as the
document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents
() in effect on the date of
publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with
respect to this document. Code Components extracted from this
document must include Simplified BSD License text as described in
Section 4.e of the Trust Legal Provisions and are provided without
warranty as described in the Simplified BSD License.
Table of Contents
. Introduction
. Requirements Language
. TinyMT32 PRNG Specification
. TinyMT32 Source Code
. TinyMT32 Usage
. Specific Implementation Validation and Deterministic Behavior
. Security Considerations
. IANA Considerations
. References
. Normative References
. Informative References
Acknowledgments
Authors' Addresses
Introduction
This document specifies the TinyMT32 PRNG as a specialization of the
reference implementation version 1.1 (2015/04/24) by Mutsuo Saito and Makoto
Matsumoto from Hiroshima University, which can be found at (the TinyMT website) and
(the GitHub site).
This specialization aims at having a simple-to-use and deterministic PRNG, as explained below.
However, the TinyMT32 PRNG is not meant to be used for cryptographic applications.
TinyMT is a new, small-sized variant of the Mersenne
Twister (MT) PRNG introduced in 2011 .
This document focuses on the TinyMT32 variant (rather than TinyMT64) of the TinyMT PRNG, which outputs 32-bit unsigned integers.
The purpose of TinyMT is not to replace the Mersenne Twister: TinyMT has a far shorter period (2127 - 1) than MT.
The merit of TinyMT is in the small size of the 127-bit internal state, far smaller than the 19937 bits of MT.
The outputs of TinyMT satisfy several statistical tests for non-cryptographic randomness, including BigCrush
in TestU01 and AdaptiveCrush , leaving it well placed
for non-cryptographic usage, especially given the small size of its internal state
(see ).
From this point of view, TinyMT32 represents a major improvement with respect
to the Park-Miller Linear Congruential PRNG (e.g., as specified in ), which suffers from several known
limitations (see, for instance, ,
Section 7.1, p. 279 and ).
The TinyMT32 PRNG initialization depends, among other things, on a parameter set, namely (mat1, mat2, tmat).
In order to facilitate the use of this PRNG and to make the sequence of pseudorandom numbers depend only on the seed value, this specification requires the use of a specific parameter set (see ).
This is a major difference with respect to the implementation version 1.1
(2015/04/24), which leaves this parameter set unspecified.
Finally, the determinism of this PRNG for a given seed has been carefully checked (see ).
This means that the same sequence of pseudorandom numbers should be generated, no matter the target execution platform and compiler, for a given initial seed value.
This determinism can be a key requirement, as is the case with , which normatively depends on this specification.
Requirements Language
The key words "MUST", "MUST NOT",
"REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT",
"RECOMMENDED", "NOT RECOMMENDED",
"MAY", and "OPTIONAL" in this document are to be
interpreted as described in BCP 14 when, and only when, they appear in all capitals, as
shown here.
TinyMT32 PRNG SpecificationTinyMT32 Source Code
The TinyMT32 PRNG must be initialized with a parameter set that needs to be well chosen.
In this specification, for the sake of simplicity, the following parameter set MUST be used:
mat1 = 0x8f7011ee = 2406486510
mat2 = 0xfc78ff1f = 4235788063
tmat = 0x3793fdff = 932445695
This parameter set is the first entry of the precalculated parameter sets in tinymt32dc/tinymt32dc.0.1048576.txt by Kenji Rikitake, available at .
This is also the parameter set used in .
The TinyMT32 PRNG reference implementation is reproduced in .
This is a C language implementation written for C99 .
This reference implementation differs from the original source code as follows:
The original authors, who are coauthors of this document, have
granted IETF
the rights to publish this version with a license and copyright that are in
accordance with BCP 78 and the IETF Trust's Legal Provisions Relating to IETF
Documents (http://trustee.ietf.org/license-info).
The source code initially spread over the tinymt32.h and tinymt32.c files has been merged.
The unused parts of the original source code have been removed.
This is the case of the tinymt32_init_by_array() alternative initialization function.
This is also the case of the period_certification() function after having checked it is not required with the chosen parameter set.
The unused constants TINYMT32_MEXP and TINYMT32_MUL have been removed.
The appropriate parameter set has been added to the initialization function.
The function order has been changed.
Certain internal variables have been renamed for compactness purposes.
The const qualifier has been added to the constant definitions.
The code that was dependent on the representation of negative integers by 2's complements has been replaced by a more portable version.
TinyMT32 Usage
This PRNG MUST first be initialized with the following function:
It takes as input a 32-bit unsigned integer used as a seed (note that value 0 is permitted by TinyMT32).
This function also takes as input a pointer to an instance of a tinymt32_t
structure that needs to be allocated by the caller but is left uninitialized.
This structure will then be updated by the various TinyMT32 functions in order to keep the internal state of the PRNG.
The use of this structure admits several instances of this PRNG to be used in parallel, each of them having its own instance of the structure.
Then, each time a new 32-bit pseudorandom unsigned integer between 0 and 232 - 1 inclusive is needed, the following function is used:
Of course, the tinymt32_t structure must be left unchanged by the caller between successive calls to this function.
Specific Implementation Validation and Deterministic Behavior
For a given seed, PRNG determinism can be a requirement (e.g., with ).
Consequently, any implementation of the TinyMT32 PRNG in line with this specification MUST have the same output as that provided by the reference implementation of .
In order to increase the compliancy confidence, this document proposes the following criteria.
Using a seed value of 1, the first 50 values returned by tinymt32_generate_uint32(s) as 32-bit unsigned integers
are equal to the values provided in , which
are to be read line by line.
Note that these values come from the tinymt/check32.out.txt file provided by the PRNG authors to validate implementations
of TinyMT32 as part of the MersenneTwister-Lab/TinyMT GitHub repository.
In particular, the deterministic behavior of the source code has been checked across several platforms:
high-end laptops running 64-bit Mac OS X and Linux/Ubuntu;
a board featuring a 32-bit ARM Cortex-A15 and running 32-bit Linux/Ubuntu;
several embedded cards featuring either an ARM Cortex-M0+, a Cortex-M3, or a Cortex-M4 32-bit microcontroller, all of them running RIOT ;
two low-end embedded cards featuring either a 16-bit microcontroller (TI MSP430) or an 8-bit microcontroller (Arduino ATMEGA2560), both of them running RIOT.
This specification only outputs 32-bit unsigned pseudorandom numbers and does not try to map this output to a smaller integer range (e.g., between 10 and 49 inclusive).
If a specific use case needs such a mapping, it will have to provide its own function.
In that case, if PRNG determinism is also required, the use of a floating point
(single or double precision) to perform this mapping should probably be
avoided, as these calculations may lead to different rounding errors across different target platforms.
Great care should also be taken to not introduce biases in the randomness of the mapped output (which may be the case with some mapping algorithms) incompatible with the use-case requirements.
The details of how to perform such a mapping are out of scope of this document.
Security Considerations
The authors do not believe the present specification generates specific
security risks per se. However, the TinyMT and MT PRNG must not be used for
cryptographic applications.
IANA Considerations
This document has no IANA actions.
ReferencesNormative ReferencesProgramming languages - C: C99, correction 3:2007International Organization for StandardizationKey words for use in RFCs to Indicate Requirement LevelsIn many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.Ambiguity of Uppercase vs Lowercase in RFC 2119 Key WordsRFC 2119 specifies common key words that may be used in protocol specifications. This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.Informative ReferencesAutomation of Statistical Tests on Randomness to Obtain Clearer ConclusionMonte Carlo and Quasi-Monte Carlo Methods 2008RIOT: An Open Source Operating System for Low-End Embedded Devices in the IoTIEEE Internet of Things Journal, Volume 5, Issue 6TinyMT pseudo random number generator for ErlangProceedings of the 11th ACM SIGPLAN Erlang Workshop, pp. 67-72Mersenne twister: A 623-dimensionally equidistributed uniform pseudo-random number generatorACM Transactions on Modeling and Computer Simulation (TOMACS), Volume 8, Issue 1, pp. 3-30Numerical recipes in C (2nd ed.): the art of scientific computingCambridge University PressLow Density Parity Check (LDPC) Staircase and Triangle Forward Error Correction (FEC) SchemesThis document describes two Fully-Specified Forward Error Correction (FEC) Schemes, Low Density Parity Check (LDPC) Staircase and LDPC Triangle, and their application to the reliable delivery of data objects on the packet erasure channel (i.e., a communication path where packets are either received without any corruption or discarded during transmission). These systematic FEC codes belong to the well- known class of "Low Density Parity Check" codes, and are large block FEC codes in the sense of RFC 3453. [STANDARDS-TRACK]Sliding Window Random Linear Code (RLC) Forward Erasure Correction (FEC) Schemes for FECFRAMETestU01: A C library for empirical testing of random number generatorsACM Transactions on Mathematical Software (TOMS), Volume 33, Issue 4, Article 22Tiny Mersenne Twister (TinyMT)TinyMT pre-calculated parameter listTiny Mersenne Twister (TinyMT)Acknowledgments
The authors would like to thank Belkacem Teibi, with whom we explored TinyMT32
specificities when looking to an alternative to the Park-Miller Linear
Congruential PRNG. The authors would also like to thank Carl Wallace; Stewart
Bryant; Greg Skinner; Mike Heard; the three TSVWG chairs, Wesley Eddy (our
shepherd), David Black, and Gorry Fairhurst; as well as Spencer Dawkins and
Mirja Kuehlewind. Last but not least, the authors are really grateful to the
IESG members, in particular Benjamin Kaduk, Eric Rescorla, Adam Roach, Roman
Danyliw, Barry Leiba, Martin Vigoureux, and Eric Vyncke for their highly
valuable feedback that greatly contributed to improving this specification.
Authors' AddressesHiroshima UniversityJapansaito@math.sci.hiroshima-u.ac.jpHiroshima UniversityJapanm-mat@math.sci.hiroshima-u.ac.jpINRIAUniv. Grenoble AlpesFrancevincent.roca@inria.frINRIAFranceemmanuel.baccelli@inria.fr