#random #rand #rng #mt

no-std rand_mt

Reference Mersenne Twister random number generators

3 stable releases

4.0.1 Feb 25, 2021
4.0.0 Dec 27, 2020
3.0.0 Mar 18, 2020
2.0.0 Mar 15, 2020

#109 in Algorithms

Download history 11/week @ 2021-06-05 12/week @ 2021-06-12 168/week @ 2021-06-19 34/week @ 2021-06-26 73/week @ 2021-07-03 279/week @ 2021-07-10 190/week @ 2021-07-17 49/week @ 2021-07-24 58/week @ 2021-07-31 43/week @ 2021-08-07 57/week @ 2021-08-14 95/week @ 2021-08-21 26/week @ 2021-08-28 5/week @ 2021-09-04 64/week @ 2021-09-11 47/week @ 2021-09-18

143 downloads per month
Used in palette




GitHub Actions Discord Twitter
Crate API API trunk

Implemenents a selection of Mersenne Twister random number generators.

A very fast random number generator of period 219937-1. (Makoto Matsumoto, 1997).

The Mersenne Twister algorithms are not suitable for cryptographic uses, but are ubiquitous. See the Mersenne Twister website. A variant of Mersenne Twister is the default PRNG in Ruby.

This crate optionally depends on rand_core and implements RngCore on the RNGs in this crate.


Add this to your Cargo.toml:

rand_mt = "4"

Then create a RNG like:

use rand_mt::Mt64;

let mut rng = Mt64::new_unseeded();
assert_ne!(rng.next_u64(), rng.next_u64());

Crate Features

rand_mt is no_std compatible. rand_mt has several optional features that are enabled by default:

  • rand-traits - Enables a dependency on rand_core. Activating this feature implements RngCore and SeedableRng on the RNGs in this crate.
  • std - Enables a dependency on the Rust Standard Library. Activating this feature enables std::error::Error impls on error types in this crate.

Mersenne Twister requires ~2.5KB of internal state. To make the RNGs implemented in this crate practical to embed in other structs, you may wish to store the RNG in a Box.

Minimum Supported Rust Version

This crate requires at least Rust 1.47.0. This version can be bumped in minor releases.


rand_mt is distributed under the terms of either the MIT License or the Apache License (Version 2.0).

rand_mt is derived from rust-mersenne-twister @ 1.1.1 which is Copyright (c) 2015 rust-mersenne-twister developers.