{"id":21048440,"url":"https://github.com/torao/tinymt","last_synced_at":"2025-05-15T19:32:15.424Z","repository":{"id":57669892,"uuid":"239350070","full_name":"torao/tinymt","owner":"torao","description":"🔢 Rust implementation for TinyMT 64/32 - a lightweight variant of the Mersenne Twister PRNG","archived":false,"fork":false,"pushed_at":"2023-06-29T17:49:35.000Z","size":826,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T08:52:24.640Z","etag":null,"topics":["mersenne-twister","prng","random","rust","tinymt"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/tinymt","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/torao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2020-02-09T18:08:03.000Z","updated_at":"2025-04-01T22:48:30.000Z","dependencies_parsed_at":"2023-02-10T02:01:49.828Z","dependency_job_id":null,"html_url":"https://github.com/torao/tinymt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torao%2Ftinymt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torao%2Ftinymt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torao%2Ftinymt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torao%2Ftinymt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/torao","download_url":"https://codeload.github.com/torao/tinymt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254407461,"owners_count":22066252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mersenne-twister","prng","random","rust","tinymt"],"created_at":"2024-11-19T14:43:30.092Z","updated_at":"2025-05-15T19:32:15.150Z","avatar_url":"https://github.com/torao.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# TinyMT\n\n[![Release Build Status for Linux](https://github.com/torao/tinymt/actions/workflows/build.yml/badge.svg)](https://github.com/torao/tinymt/actions)\n[![Test Status](https://github.com/torao/tinymt/actions/workflows/test.yml/badge.svg)](https://github.com/torao/tinymt/actions)\n[![docs](https://docs.rs/tinymt/badge.svg)](https://docs.rs/tinymt)\n[![crates.io](https://img.shields.io/crates/v/tinymt.svg)](https://crates.io/crates/tinymt)\n\nRust implementation of TinyMT 64/32 - a lightweight variant of Mersenne Twister PRNG.\n\nThis crate is based on the original [TinyMT 1.1.1](https://github.com/MersenneTwister-Lab/TinyMT) @ 9d7ca3c161\nimplemented in C.\n\n## Features\n\n**TinyMT** is a lightweight variant of **Mersenne Twister** MT19937, a widely used PRNG (pseudo-random number generator). This is useful in the case where you don't need so a long period as MT19937, but need sufficient randomness and speed with less memory.\n\nThis algorithm works with only 16B internal state space, which is much smaller than the 2,500B of MT19937. The period is\n2¹²⁷-1, it's shorter than MT19937 but sufficient for practical use. The cost to generate one random number\nwas as fast as 4ns on Intel Core i7-8550U CPU.\n\nThis crate provides the following two TinyMT implementations for both `std` and `no_std` environments.\n\n* TinyMT32 (32-bit version) for `u32` and `f32`. This is also defined as [RFC 8682](https://tools.ietf.org/html/rfc8682) by IEFT.\n* TinyMT64 (64-bit version) for `u64` and `f64`.\n\nTinyMT32 has also been used for random numbers to control which monsters will hatch in Pokémon.\n\nNote that neither TinyMT nor MT 19937 are cryptographically secure pseudo-random number generators. You shouldn't use them in applications where high security is required, such as the generation of private keys.\n\n## Getting Started\n\nYou'll be able to use TinyMT by simply adding the dependency to `Cargo.toml` of your project.\n\n```toml\n[dependencies]\nrand = \"0.8\"\ntinymt = \"1.0\"\n```\n\nBy declaring `tinymt` crate at the beginning of the source code, you can use `TinyMT64` or `TinyMT32` to obtain random numbers.\n\n```rust\nextern crate tinymt;\n\nuse rand::{Rng, SeedableRng};\nuse tinymt::{TinyMT64, TinyMT64Seed};\n\nfn main() {\n  // from nondeterministic seed\n  let mut random = TinyMT64::from_entropy();\n  let rn = random.gen_range(0.0..1.0);\n  println!(\"{}\", rn);   // =\u003e nondeterministic but such that 0.3487526381670172\n\n  // from deterministic seed (reproduction of random number sequence is possible)\n  let mut random = TinyMT64::from_seed(TinyMT64Seed::from(0u64));\n  let rn = random.gen_range(0.0..1.0);\n  println!(\"{}\", rn);   // =\u003e 0.5531250908497853\n}\n```\n\nThe `TinyMT64` and `TinyMT32` respectively implement the `rand::RngCore` features that are widely-used PRNG interface in Rust. Note that 64-bit operations for `TinyMT32` will generate 32-bit random numbers two times at once for the compatibility of `RngCore`. You should use `u32` or `f32` random number to achieve the best performance in `TinyMT32`.\n\n### Lower-level API\n\nThis crate contains two modules `tinymt::tinymt64` and `tinymt::tinymt32` that have been migrated from the original C implementation. They might be useful if you are familiar with the original C implementation. Also, since they are independent of external libraries, it's able to avoid some conflict problems.\n\nSee [the API Reference](https://docs.rs/tinymt) for all functions.\n\n## How to Build\n\nThe followings are typical `cargo` commands used to test, verify the quality of TinyMT.\n\n```shell\ncargo test\ncargo clippy\ncargo fmt       # or fmt -- --check\n```\n\n## WebAssembly Support\n\nTinyMT is fully available in Rust code targeting WebAssembly (WASM). If `wasmer` is set up in your environment, you can run `cargo test --target wasm32-wasi`. See also [.cargo/config](.cargo/config)\n\nIf your target doesn't support WASI, like `wasm32-unknown-unknown`, the entropy-based seeding from OS isn't automatically supported. In this case, you can use TinyMT either by using an application-defined seed without using `from_entropy()`, or if the target supports JS such as a browser, by making `getrandom()` dependent on JS as follow.\n\n```toml\n[dependencies]\ngetrandom = { version = \"0.2\", features = [\"js\"] }\n```\n\nSee [the description of getrandom](https://docs.rs/getrandom/latest/getrandom/#webassembly-support) for more information.\n\n## Histories\n\n* 2023-06-30 (v1.0.9) Add support for WebAssembly.\n* 2023-03-15 (v1.0.8) `no-std` available.\n* 2022-05-19 (v1.0.7) Migrate the project to 2021 edition.\n* 2021-06-12 (v1.0.6) Upgrade `rand` to 0.8.\n\n## Licenses\n\nMIT License\n\nCopyright (c) 2023 Torao Takami\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n## See Also\n\n* [Mersenne Twister Home Page](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/mt.html)\n* [Tiny Mersenne Twister (TinyMT): A small-sized variant of Mersenne Twister](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/index.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorao%2Ftinymt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftorao%2Ftinymt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorao%2Ftinymt/lists"}