Skip to content
artichokePublic

About

🌪 Mersenne Twister implementation backed by rand_core

Topics

Resources

Contributing

Stars

27 stars

Watchers

4 watching

Forks

Repository files navigation

rand_mt

GitHub Actions Crate API

Reference MT19937 (Mt) and MT19937-64 (Mt64) pseudorandom number generators. Artichoke uses Mt to reproduce Ruby random number sequences.

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 0.10 and implements TryRng with an Infallible error, which also provides Rng through a blanket impl.

Usage

Add this to your Cargo.toml:

[dependencies]
rand_mt = "6.1.0"

Then create a RNG with an explicit seed:

use rand_mt::Mt64;

let mut rng = Mt64::new(0x0123_4567_89ab_cdef_u64);
assert_ne!(rng.next_u64(), rng.next_u64());

Mt::new_unseeded() and Mt64::new_unseeded() are deterministic shortcuts for the reference seed. They are intended for reproducible streams and tests and do not gather entropy.

Crate Features

rand_mt is no_std and does not require alloc. It has one optional feature, enabled by default:

  • rand-traits - Enables a dependency on rand_core. Activating this feature implements TryRng and SeedableRng on the RNGs in this crate, with Rng provided by rand_core.

Disable the default feature to use the generators without dependencies:

[dependencies]
rand_mt = { version = "6.1.0", default-features = false }

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.88.0. This version can be bumped in minor releases. Rust 1.88 enables typed slice chunks for byte filling.

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.

About

🌪 Mersenne Twister implementation backed by rand_core

Topics

Resources

Contributing

Stars

27 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages