voxell_rng

Crates.iovoxell_rng
lib.rsvoxell_rng
version
sourcesrc
created_at2024-11-16 03:29:49.965788
updated_at2024-11-24 02:07:25.800943
descriptionCheap and dirty thread-local RNGs
homepage
repositoryhttps://github.com/paladynee/voxell_rng
max_upload_size
id1449885
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Voxell Paladynee (Paladynee)

documentation

https://docs.rs/voxell_rng

README

Cheap and dirty RNGs

use voxell_rng::prelude::*;
use voxell_rng::time_seeded::TimeSeededXorShift32;
// seeds using os entropy
let mut rng = TimeSeededXorShift32::generate().unwrap();
rng.next_u32();

Welcome to the land of unreproducible builds

Use this crate if you need simple random number generators for your project and you don't want to depend on a big library like rand.

You can seed your RNGs using the system time [voxell_rng::time_seeded] or runtime entropy [voxell_rng::runtime_seeded].

There are 5 RNGs available:

  • SplitMix64: a 64-bit RNG with 64-bit output used for seeding other RNGs
  • XorShift32: a 32-bit Xorshift RNG with 32-bit output
  • XorShift128: a 128-bit Xorshift RNG with 64-bit output (Recommended)
  • XoRoShiRo128: a 128-bit XoRoShiRo RNG with 64-bit output
  • Pcg8 through Pcg128: the PCG family of RNGs

All RNGs implement BranchRng which is a simple trait that provides a branch_rng method for creating a new divergent RNG from the current one. The resulting RNG will have a different state and will produce different random numbers without needing to specify a new seed.

Examples

  1. Create a new RNG using a constant seed and use it:
use voxell_rng::rng::XorShift32;

// create the rng
let mut rng = XorShift32::new(0xcafebabe as u64);

// generate a new number
rng.next_f32();
  1. Seed your RNGs using the system time
use voxell_rng::time_seeded::TimeSeededXorShift32;
let mut rng = TimeSeededXorShift32::generate().unwrap();
rng.next_f32();
  1. Seed your RNGs using runtime entropy
use voxell_rng::rng::XorShift32;
// Default implementation for non-PCG RNG's use OS entropy
let mut rng = XorShift32::default();
rng.next_f32();
  1. Create new RNGs from a master RNG for divergent thread local RNGs:
use voxell_rng::prelude::*;
use voxell_rng::rng::XoRoShiRo128;

let mut master_rng = XoRoShiRo128::new(0xabad1dea as u64);
let thread_handles = (0..16)
    .map(|_| {
        let rng = master_rng.branch_rng();
        std::thread::spawn(move || {
            let mut thread_local_rng = rng;
            for _ in 0..1000 {
                thread_local_rng.next_u64();
            }
        })
    })
    .collect::<Vec<_>>();
Commit count: 11

cargo fmt