multirand

Crates.iomultirand
lib.rsmultirand
version0.2.0
created_at2025-12-20 17:22:21.984765+00
updated_at2026-01-11 08:14:36.498997+00
descriptionA threaded pseudo-random number generator
homepagehttps://codeberg.org/shelter_kytty/async-rand
repositoryhttps://codeberg.org/shelter_kytty/async-rand
max_upload_size
id1996752
size22,821
shelter_kytty (shelter-kytty)

documentation

README

multirand

Latest Version Documentation License

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.


Usage

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 --- */
}
Commit count: 35

cargo fmt