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
/*!
Produce and consume randomness.
This crate provides utilities to generate random numbers, to convert them to useful types and distributions, and some randomness-related algorithms.
This library is inspired by the semi-official [`rand`](https://crates.io/crates/rand) crate and an attempt to provide a better experience.
# Quick Start
To get you started quickly, the easiest and highest-level way to get a random value is to use `urandom::new().next()`.
The [`Random`] struct provides a useful API on all [`Rng`], while the [`distr`] module provide specific distributions on top of Rngs.
```
let mut rand = urandom::new();
// Generates a random boolean
if rand.coin_flip() {
// Try printing a random unicode code point (probably a bad idea)!
println!("char: {}", rand.next::<char>());
}
// Generates a float between 13.0 and 42.0
let y: f64 = rand.range(13.0..42.0);
// Shuffles the list of numbers
let mut numbers: Vec<i32> = (1..100).collect();
rand.shuffle(&mut numbers);
```
*/
// Unsafe code is restricted to certain specific Rng implementations
pub use Rng;
pub use Distribution;
pub use Random;
//----------------------------------------------------------------
/// Creates a new instance of the default PRNG.
///
/// The generator is seeded securely from the system entropy source.
///
/// # Examples
///
/// ```
/// let mut rand = urandom::new();
/// let value: i32 = rand.next();
/// ```
/// Creates a new instance of the default PRNG with the given seed.
///
/// The seed does not need to look random, the PRNG constructor ensures it can handle degenerate seed values.
///
/// This function guarantees that the same seed always produces the same sequence of randomness.
///
/// # Examples
///
/// ```
/// let mut rand = urandom::seeded(42);
/// let value: i32 = rand.next();
/// assert_eq!(value, 368317477);
/// ```
/// Creates a new cryptographically secure PRNG.
///
/// The generator is seeded securely from the system entropy source.
///
/// # Examples
///
/// ```
/// let mut rand = urandom::csprng();
/// let value: i32 = rand.next();
/// ```