rand_mt_64

Crates.iorand_mt_64
lib.rsrand_mt_64
version0.1.3
created_at2025-07-06 06:29:43.660325+00
updated_at2025-07-06 06:58:13.238171+00
descriptionA high-resolution random number generator using Mersenne Twister 64
homepage
repositoryhttps://github.com/mahib1/randMT64.git
max_upload_size
id1739856
size11,409
(mahib1)

documentation

README

randMT64

A lightweight, fast, and high-resolution pseudo-random number generator in Rust based on the Mersenne Twister 64-bit algorithm โ€” with support for u128 outputs and floating-point results mapped to any configurable range.

Crate name: randMT64
Module root: rand_num_gen
Author: @mahib1


๐ŸŒŸ Features

  • โš™๏ธ Pure Rust implementation of MT19937-64
  • ๐Ÿ” Generates 128-bit numbers by combining two 64-bit outputs
  • ๐Ÿ•’ Microsecond-precision time-based seeding using SystemTime
  • ๐ŸŽš Range mapping to produce f64 outputs in any interval
  • ๐Ÿงช Deterministic, seedable output โ€” perfect for simulations and research
  • ๐Ÿชถ Lightweight and dependency-free (except std)

๐Ÿ“ฆ Usage

Add to your Cargo.toml:

[dependencies]
rand_mt_64 = "0.1.2"

Use in code:

use rand_mt_64::{rand, RandomRange};

fn main() {
    let r1 = rand(RandomRange::default()).unwrap();
    println!("Random float [0, 1): {}", r1);

    let r2 = rand(RandomRange::new(10, 100)).unwrap();
    println!("Random float [10, 100): {}", r2);
}

๐Ÿ“ Crate Structure

rand_mt_64/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ lib.rs           # Public API
โ”‚   โ”œโ”€โ”€ mt64.rs          # Mersenne Twister 64-bit implementation
โ”‚   โ”œโ”€โ”€ time.rs          # SystemTime-based seeding
โ”‚   โ””โ”€โ”€ range.rs         # RandomRange config and mapping
โ”œโ”€โ”€ examples/
โ”‚   โ””โ”€โ”€ usage.rs         # Sample usage
โ”œโ”€โ”€ Cargo.toml
โ””โ”€โ”€ README.md

๐Ÿ”ง API Overview

rand(config: &RandomRange) -> Result<f64, std::io::Error>

  • Generates a pseudo-random f64 in the interval [config.start, config.end)
  • Internally uses the current system time (in microseconds) to seed a new MT64 instance

RandomRange::new(start: u128, end: u128)

  • Configure a custom output range

RandomRange::default()

  • Shortcut for range [0, 1) using the MAGIC resolution constant

๐Ÿ“œ License

Licensed under either of:


๐Ÿšง TODOs

  • Optional persistent seeding
  • Support for no_std
  • Unit and randomness quality tests
  • Expose MersenneTwister64 directly via the crate root

๐Ÿค” Why randMT64?

Because rand is too big, and rand_core is too low-level. This is the minimalist, high-precision, configurable u128 solution you didnโ€™t know you needed.


๐Ÿ‘ค Author

Built by @mahib1

Commit count: 0

cargo fmt