| Crates.io | xorwowgen |
| lib.rs | xorwowgen |
| version | 0.4.0 |
| created_at | 2024-08-15 11:47:06.294156+00 |
| updated_at | 2024-09-08 10:42:54.101093+00 |
| description | Several implementations of the Xorwow algorithm |
| homepage | |
| repository | https://github.com/elkasztano/xorwow |
| max_upload_size | |
| id | 1338616 |
| size | 23,922 |
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.
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);
}
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.