19
19
//! [`SeedableRng`] is an extension trait for construction from fixed seeds and
20
20
//! other random number generators.
21
21
//!
22
- //! [`Error`] is provided for error-handling. It is safe to use in `no_std`
23
- //! environments.
24
- //!
25
22
//! The [`impls`] and [`le`] sub-modules include a few small functions to assist
26
23
//! implementation of [`RngCore`].
27
24
//!
@@ -68,11 +65,6 @@ pub mod le;
68
65
/// [`next_u32`] and [`next_u64`] methods, implementations may discard some
69
66
/// random bits for efficiency.
70
67
///
71
- /// The [`try_fill_bytes`] method is a variant of [`fill_bytes`] allowing error
72
- /// handling; it is not deemed sufficiently useful to add equivalents for
73
- /// [`next_u32`] or [`next_u64`] since the latter methods are almost always used
74
- /// with algorithmic generators (PRNGs), which are normally infallible.
75
- ///
76
68
/// Implementers should produce bits uniformly. Pathological RNGs (e.g. always
77
69
/// returning the same value, or never setting certain bits) can break rejection
78
70
/// sampling used by random distributions, and also break other RNGs when
@@ -128,7 +120,6 @@ pub mod le;
128
120
/// ```
129
121
///
130
122
/// [`rand`]: https://docs.rs/rand
131
- /// [`try_fill_bytes`]: RngCore::try_fill_bytes
132
123
/// [`fill_bytes`]: RngCore::fill_bytes
133
124
/// [`next_u32`]: RngCore::next_u32
134
125
/// [`next_u64`]: RngCore::next_u64
@@ -151,11 +142,7 @@ pub trait RngCore {
151
142
///
152
143
/// RNGs must implement at least one method from this trait directly. In
153
144
/// the case this method is not implemented directly, it can be implemented
154
- /// via [`impls::fill_bytes_via_next`] or
155
- /// via [`RngCore::try_fill_bytes`]; if this generator can
156
- /// fail the implementation must choose how best to handle errors here
157
- /// (e.g. panic with a descriptive message or log a warning and retry a few
158
- /// times).
145
+ /// via [`impls::fill_bytes_via_next`].
159
146
///
160
147
/// This method should guarantee that `dest` is entirely filled
161
148
/// with new data, and may panic if this is impossible
@@ -434,6 +421,9 @@ pub trait SeedableRng: Sized {
434
421
/// This method is the recommended way to construct non-deterministic PRNGs
435
422
/// since it is convenient and secure.
436
423
///
424
+ /// Note that this method may panic on (extremely unlikely) [`getrandom`] errors.
425
+ /// If it's not desirable, use the [`try_from_entropy`] method instead.
426
+ ///
437
427
/// In case the overhead of using [`getrandom`] to seed *many* PRNGs is an
438
428
/// issue, one may prefer to seed from a local PRNG, e.g.
439
429
/// `from_rng(thread_rng()).unwrap()`.
@@ -443,6 +433,7 @@ pub trait SeedableRng: Sized {
443
433
/// If [`getrandom`] is unable to provide secure entropy this method will panic.
444
434
///
445
435
/// [`getrandom`]: https://docs.rs/getrandom
436
+ /// [`try_from_entropy`]: SeedableRng::try_from_entropy
446
437
#[ cfg( feature = "getrandom" ) ]
447
438
#[ cfg_attr( doc_cfg, doc( cfg( feature = "getrandom" ) ) ) ]
448
439
fn from_entropy ( ) -> Self {
@@ -452,10 +443,8 @@ pub trait SeedableRng: Sized {
452
443
}
453
444
}
454
445
455
- /// Creates a new instance of the RNG seeded via [`getrandom`].
456
- ///
457
- /// This method is the recommended way to construct non-deterministic PRNGs
458
- /// since it is convenient and secure.
446
+ /// Creates a new instance of the RNG seeded via [`getrandom`] without unwrapping
447
+ /// potential [`getrandom`] errors.
459
448
///
460
449
/// In case the overhead of using [`getrandom`] to seed *many* PRNGs is an
461
450
/// issue, one may prefer to seed from a local PRNG, e.g.
0 commit comments