turborand
Fast random number generators.
turborand's internal implementations use Wyrand, a simple and fast
generator but not cryptographically secure, and also ChaCha8, a cryptographically
secure generator tuned to 8 rounds of the ChaCha algorithm in order to increase throughput considerably without sacrificing
too much security, as per the recommendations set out in the Too Much Crypto paper.
Examples
use *;
let rand = new;
if rand.bool else
Sample a value from a list:
use *;
let rand = new;
let values = ;
let value = rand.sample;
Generate a vector with random values:
use *;
use repeat_with;
let rand = new;
let values: = repeat_with.take.collect;
Migration from 0.5 to 0.6
Version 0.6 introduces a major reworking of the crate, with code reorganised and also exposed more granularly via features. First things to note:
- All major exports for the crate are now in the
preludemodule. Top level only exports the new traits forturborand. Rngis now split intoRngandAtomicRng, no more top level generics that required exporting internal traits.Statetrait is now made private and no longer available to be implemented, as this was an internal implementation detail forWyRand.- All previous methods for
Rngare now implemented inTurboCore,GenCore,SeededCoreandTurboRandtraits. These are part of thepreludeso as long as they are included, all existing methods will work as expected. Rngis now under a feature flag,wyrand. This is enabled by default however, unlessdefault-features = falseis applied on the dependency declaration in Cargo.toml.- Yeet the
rng!,atomic_rng!macros, as these are no longer needed to manage the generics spam that has since been refactored out. Instead, use::new(),::default()or::with_seed(seed)methods instead.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.