Non-cryptographic PRNGs

MT19937

The classic long-period generator behind many language defaults, not for security

unverified Root API only Not cryptographic
Unverified tier.

Source found and wired, correctness not fully proven. Root API only. Reach it with NextSSL(root=True) in Python or the nextssl_root_* functions in C.

About MT19937

MT19937 is one of 2 Mersenne Twister (MT19937) variants in the NextSSL registry, a non-cryptographic pseudorandom generator. It uses a 1–268,435,456-byte output and a 4-byte seed. Its registry entry cites MT19937 (Matsumoto, Nishimura 1998), NOT cryptographically secure. It is also known as mersenne-twister. NextSSL lists it in the unverified tier and exposes it through the root API only (NextSSL(root=True) in Python, nextssl_root_* in C).

Overview

The Mersenne Twister is a pseudorandom number generator with a period of 2^19937 - 1, a 2.5 KB state and good equidistribution. It has been the default in Python, Ruby, PHP, R and C++ standard libraries for decades, but its output is fully predictable after observing enough values.

MT19937 keeps 624 32-bit words of state and generates output with a twisted generalised feedback shift register, followed by a tempering transformation that improves equidistribution. Every 624 outputs it regenerates the whole state. The construction is linear over GF(2), which gives its enormous period and fast generation but also makes it trivially invertible: the tempering is reversible, so 624 consecutive 32-bit outputs reveal the entire state.

Two variants are present: mt19937, the 32-bit generator from 1998, and mt19937-64, the 64-bit version with a 312-word state published in 2000. Modern alternatives such as PCG and xoshiro are smaller, faster and statistically stronger, as MT fails some linearity tests in TestU01's BigCrush. It also recovers slowly from states with many zero bits, a known weakness addressed by later designs such as SFMT and WELL.

History

1998–1998
  1. Mersenne Twister published by Makoto Matsumoto, Takuji Nishimura

How it works

  1. Initialise 624 (or 312 for 64-bit) state words from a seed.
  2. Regenerate the state block by combining adjacent words with a fixed twist matrix.
  3. Output each state word after a tempering sequence of shifts, ands and xors.
  4. Repeat the regeneration after every full block of outputs.

Security notes

Not cryptographically secure: observing 624 consecutive outputs allows complete state recovery and prediction of all further values. Many real vulnerabilities (password reset tokens, session IDs) came from using MT for secrets.

Typical uses

Reproducing results that depend on MT19937 sequencesLegacy simulations and statistics codeCompatibility with language default generators

Sizes

FieldBytesMeaning
out1 – 268,435,456Output
seed4Seed

Use it

from nextssl_demo import NextSSL

root = NextSSL(root=True)   # tier 'unverified' is reachable from the root API only
buf = root.call("rng_fill", "mt19937", "seed=42", 32)[0]   # not for keys

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Other Mersenne Twister (MT19937) variants

1

Frequently asked questions

What is MT19937?

MT19937 is a PRNG in the Mersenne Twister (MT19937) family. The Mersenne Twister is a pseudorandom number generator with a period of 2^19937 - 1, a 2.5 KB state and good equidistribution. It is also known as mersenne-twister.

What are the MT19937 sizes?

In NextSSL, MT19937 uses: output 1 to 268,435,456 bytes.

Who designed MT19937 and when?

MT19937 belongs to the Mersenne Twister (MT19937) family, first published in 1998 by Makoto Matsumoto, Takuji Nishimura. Its origin: Matsumoto and Nishimura, ACM Transactions on Modeling and Computer Simulation (1998).

Which standards define MT19937?

MT19937 is referenced by MT19937 (Matsumoto, Nishimura 1998), NOT cryptographically secure.

Is MT19937 safe to use?

MT19937 is in the unverified tier. Source found and wired, correctness not fully proven. Root API only. It is only reachable through the root API (NextSSL(root=True) in Python, nextssl_root_* in C).

What other Mersenne Twister (MT19937) variants are there?

NextSSL also registers mt19937-64 in the Mersenne Twister (MT19937) family.