
* rands: use splitmix64 for seeding Seeding with splitmix64 is a good way to avoid starting with low-entropy PRNG states, and is explicitly recommended by the authors of both xoshiro256++ and Romu. While at it, give the xoshiro256++ PRNG its proper name. * rands: use fast_bound() to generate number in range * rands: add top-level choose() * rands: add Rand::next_float() * rands: add Rand::coinflip() helper * libafl: unbreak tests that relied on direct seeding * rands: add SFC64 PRNG SFC64 is a well-established and well-understood PRNG designed by Chris Doty-Humphrey, the author of PractRand. It has been tested quite a lot over the years, and to date has no known weaknesses. Compared to xoshiro256++, it is slightly faster and is likely to be a more future-proof design (xoshiro/xoroshiro family of generators come with quite long history of [flaws][1] found over the years). Compared to Romu, it is slightly slower, but guarantees absense of bias, minimum period of at least 2^64 for any seed, and non-overlapping streams for different seeds. [1]: https://tom-kaitchuck.medium.com/designing-a-new-prng-1c4ffd27124d
27 lines
1.1 KiB
Rust
27 lines
1.1 KiB
Rust
//! Compare the speed of rand implementations
|
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
use libafl_bolts::rands::{
|
|
Lehmer64Rand, Rand, RomuDuoJrRand, RomuTrioRand, Sfc64Rand, XorShift64Rand,
|
|
Xoshiro256PlusPlusRand,
|
|
};
|
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
|
let mut sfc64 = Sfc64Rand::with_seed(1);
|
|
let mut xorshift = XorShift64Rand::with_seed(1);
|
|
let mut xoshiro = Xoshiro256PlusPlusRand::with_seed(1);
|
|
let mut romu = RomuDuoJrRand::with_seed(1);
|
|
let mut lehmer = Lehmer64Rand::with_seed(1);
|
|
let mut romu_trio = RomuTrioRand::with_seed(1);
|
|
|
|
c.bench_function("sfc64", |b| b.iter(|| black_box(sfc64.next())));
|
|
c.bench_function("xorshift", |b| b.iter(|| black_box(xorshift.next())));
|
|
c.bench_function("xoshiro", |b| b.iter(|| black_box(xoshiro.next())));
|
|
c.bench_function("romu", |b| b.iter(|| black_box(romu.next())));
|
|
c.bench_function("romu_trio", |b| b.iter(|| black_box(romu_trio.next())));
|
|
c.bench_function("lehmer", |b| b.iter(|| black_box(lehmer.next())));
|
|
}
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
criterion_main!(benches);
|