1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Fast random number generators.
//!
//! The implementations use [Wyrand](https://github.com/wangyi-fudan/wyhash), a simple and fast
//! generator but **not** cryptographically secure, and [ChaCha8](https://cr.yp.to/chacha.html),
//! 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](https://eprint.iacr.org/2019/1492.pdf) paper.
//!
//! # Examples
//!
//! Generate a random value:
//!
//! ```ignore
//! use turborand::prelude::*;
//!
//! let rand = Rng::new();
//!
//! let value = rand.bool();
//! ```
//!
//! Sample a value from a list:
//!
//! ```ignore
//! 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:
//!
//! ```ignore
//! use turborand::prelude::*;
//! use std::iter::repeat_with;
//!
//! let rand = Rng::new();
//!
//! let values: Vec<_> = repeat_with(|| rand.f32()).take(10).collect();
//! ```
//!
//! # Features
//!
//! The base crate will always export the [`TurboCore`], [`GenCore`],
//! [`SeededCore`], [`TurboRand`], [`SecureCore`] and [`ForkableCore`] traits, and will do
//! so when set as `default-features = false` in the Cargo.toml. By default,
//! it will have `wyrand` feature enabled as the basic PRNG exposed.
//!
//! * **`alloc`** - Enables support for boxed [`TurboCore`] references, as well
//! as [`TurboRand`] methods that return [`Vec`] results.
//! * **`fmt`** - Enables [`core::fmt::Debug`] implementations for [`rng::Rng`]
//! & [`chacha_rng::ChaChaRng`].
//! * **`std`** - Enables `std` features, such as `alloc` methods as well as
//! [`Default`] implementations for [`rng::Rng`] & [`chacha_rng::ChaChaRng`].
//! * **`wyrand`** - Enables [`rng::Rng`], so to provide a
//! basic, non-threadsafe PRNG. Enabled by default. `no-std` compatible.
//! * **`atomic`** - Enables [`rng::AtomicRng`], so
//! to provide a thread-safe variation of [`rng::Rng`]. Enables `wyrand`
//! feature implicitly. **Note**, this is slower than [`rng::Rng`].
//! * **`rand`** - Provides [`compatibility::RandCompat`], which implements [`RngCore`]
//! so to allow for compatibility with `rand` ecosystem of crates
//! * **`serialize`** - Enables [`Serialize`] and [`Deserialize`] derives on [`rng::Rng`],
//! [`rng::AtomicRng`] and [`chacha_rng::ChaChaRng`], provided they have their
//! respective features activated as well.
//! * **`chacha`** - Enables [`chacha_rng::ChaChaRng`] for providing a more cryptographically
//! secure source of Rng. Note, this will be slower than [`rng::Rng`] in
//! throughput, but will produce much higher quality randomness. `no-std` compatible.
extern crate alloc;
use Rc;
use Debug;
use Instant;
use Instant;
use RngCore;
use ;
use Visitor;
use ;
pub use ;