#random #rand #no-alloc

no-std rand_mt

Reference Mersenne Twister random number generators

9 stable releases

4.2.2 Jun 2, 2023
4.2.1 Oct 11, 2022
4.2.0 Aug 9, 2022
4.1.3 Jul 31, 2022
2.0.0 Mar 15, 2020

#106 in Algorithms

Download history 3008/week @ 2024-08-01 2454/week @ 2024-08-08 1815/week @ 2024-08-15 2388/week @ 2024-08-22 3169/week @ 2024-08-29 2341/week @ 2024-09-05 2038/week @ 2024-09-12 1689/week @ 2024-09-19 1610/week @ 2024-09-26 1888/week @ 2024-10-03 1776/week @ 2024-10-10 2194/week @ 2024-10-17 4114/week @ 2024-10-24 2222/week @ 2024-10-31 2023/week @ 2024-11-07 1679/week @ 2024-11-14

10,513 downloads per month
Used in 7 crates (4 directly)

MIT/Apache

160KB
5K SLoC

rand_mt

GitHub Actions Code Coverage Discord Twitter
Crate API API trunk

Implements 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.

Usage

Add this to your Cargo.toml:

[dependencies]
rand_mt = "4.2.2"

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 approximately 2.5 kilobytes 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.

License

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.

Dependencies