Crates.io | block-pseudorand |
lib.rs | block-pseudorand |
version | 0.1.2 |
source | src |
created_at | 2021-09-18 07:39:34.794311 |
updated_at | 2022-03-28 13:16:49.689722 |
description | Generator of random Vec |
homepage | |
repository | |
max_upload_size | |
id | 453228 |
size | 19,990 |
This crate allows multi-threaded creation of pseudorandom Vec<T>
's of arbitrary length. It does this
by generating arbitrary byte vectors randomly and transmuting to the provided type.
Warning: This is wildly unsafe for some types as it does not uphold any invariants your type might expect. Only use this crate if your type can be safely generated from completely arbitrary bytes. Generally, this means your type should consist of nothing but primitive numbers such as u32, i64, or f32.
If you need a lot of random numbers quickly for something non-production critical like unit tests, this may be a good candidate. Otherwise, if you are planning to use this at runtime, or with types that are non-numeric or otherwise cannot be created from arbitrary bytes, I would recommend you to choose another, safer crate.
If you are certain the above warnings do not apply to the type you are generating, you can use this library like so:
use block_pseudorand::block_rand;
let random_data: Vec<u64> = block_rand(128);
assert_eq!(random_data.len(), 128);
use block_pseudorand::block_rand_with_seed;
// Populate this seed as you wish
let seed = [0u8; 32];
let random_data: Vec<u64> = block_rand_with_seed(128, &seed);
assert_eq!(random_data.len(), 128);