turborand

CI License Cargo Documentation

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

```rust use turborand::prelude::*;

let rand = Rng::new();

if rand.bool() { println!("Success! :D"); } else { println!("Failure... :("); } ```

Sample a value from a list:

```rust use turborand::prelude::*;

let rand = Rng::new();

let values = [1, 2, 3, 4, 5];

let value = rand.sample(&values); ```

Generate a vector with random values:

```rust use turborand::prelude::*; use std::iter::repeat_with;

let rand = Rng::new();

let values: Vec<_> = repeat_with(|| rand.f32()).take(10).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:

Migration from 0.6 to 0.7

Version 0.7 hasn't changed much except that the internals module is now fully private (so the State traits and CellState/AtomicState structs are no longer public). They are not accessible from the prelude any more. The removal of these from the public API thus constitutes a breaking change, leading to a new major version.

Also, the serialisation format of ChaChaRng has changed, so 0.7 is not compatible with older serialised structs. The plus side is also a flatter serialised format for ChaChaRng. Also, ChaChaRng is no longer backed by a Vec for caching generated entropy, now preferring to use an aligned array for better random number generation at the slight cost of initialisation/cloning performance and increased struct size. This means that the single heap allocation ChaChaRng needed is now reduced to zero.

License

Licensed under either of

at your option.