xorwowgen

Crates.ioxorwowgen
lib.rsxorwowgen
version0.4.0
sourcesrc
created_at2024-08-15 11:47:06.294156
updated_at2024-09-08 10:42:54.101093
descriptionSeveral implementations of the Xorwow algorithm
homepage
repositoryhttps://github.com/elkasztano/xorwow
max_upload_size
id1338616
size23,922
(elkasztano)

documentation

README

Xorwow Generators

Several implementations of the Xorwow generator as proposed here:

https://www.jstatsoft.org/article/view/v008i14

Implements the SeedableRng and RngCore traits from rand_core, so the crate may be used to create various kinds of pseudorandom number sequences.

Examples

Get a few pseudorandom u32 integers:

use rand_core::{SeedableRng, RngCore}; // version = "0.6.4"
use xorwowgen::Xorwow160;

fn main() {
    // initialize the pseudorandom number generator
    let mut rng = Xorwow160::seed_from_u64(123456789);

    // clock it a few times
    for _ in 0..100 {
        rng.next_u32();
    }

    // generate a few numbers
    for _ in 0..10 {
        println!("{}", rng.next_u32());
    }
}

Shuffle mutable array:

use xorwowgen::xorwow64::WrapA;
use rand::SeedableRng; // version = "0.8.5"
use rand::seq::SliceRandom;

fn main() {
    // initialize with true random bytes
    let mut rng = WrapA::from_entropy();

    let mut my_data = ["foo", "bar", "baz", "qux"];

    // shuffle data and print the result
    my_data.shuffle(&mut rng);
    println!("{:?}", &my_data);

    // shuffle again ...
    my_data.shuffle(&mut rng);
    println!("{:?}", &my_data);
}

Notes

  • The generators in this crate are not suitable for any kind of cryptographical use.

  • If you need more functionality than just generating u32 or u64 integers, I highly recommend to have a look at the rand book. As mentioned above, SeedableRng and RngCore are implemented.

Commit count: 0

cargo fmt