| Crates.io | multirand |
| lib.rs | multirand |
| version | 0.2.0 |
| created_at | 2025-12-20 17:22:21.984765+00 |
| updated_at | 2026-01-11 08:14:36.498997+00 |
| description | A threaded pseudo-random number generator |
| homepage | https://codeberg.org/shelter_kytty/async-rand |
| repository | https://codeberg.org/shelter_kytty/async-rand |
| max_upload_size | |
| id | 1996752 |
| size | 22,821 |
A threaded prng.
Adds a single struct ThreadRandom for generating random numbers. Each instance of ThreadRandom has it's own threaded randomiser, the goal being to avoid correlation between successive values by avoiding the use of successive values entirely.
This is not a cryptographically secure implementation of prng, nor is it a performant one. Non-threaded crates with better randomisation functions will work just as well if not better. This is largely a toy, vaguely inspired by the dedicated LFSR chips or processers used in games and computers in the early digital era. If you were to use it, it would in theory be best suited to situations where a "continuous trickle" of random numbers is required, as it will fail to build up entropy when polled continuously.
Add the following to your Cargo.toml:
[dependencies]
multirand = "0.2.0"
Or add with cargo:
cargo add multirand
Instance ThreadRandom in your project and poll it for random values:
use multirand::ThreadRandom;
let rand = ThreadRandom::os().unwrap();
fn randomised_behaviour() {
/* --- snip --- */
let tiebreaker = rand.random::<u8>().unwrap() % 4;
if (tiebreaker == 0) { /* ... */
/* --- snip --- */
}