9
9
//! Interface to the random number generator of the operating system.
10
10
// Note: keep this code in sync with the rand_os crate!
11
11
12
- use crate :: getrandom:: getrandom;
13
- use rand_core :: { CryptoRng , RngCore , Error , impls} ;
12
+ use getrandom:: getrandom;
13
+ use crate :: { CryptoRng , RngCore , Error , impls} ;
14
14
15
15
/// A random number generator that retrieves randomness from from the
16
16
/// operating system.
@@ -20,6 +20,9 @@ use rand_core::{CryptoRng, RngCore, Error, impls};
20
20
/// The implementation is provided by the [getrandom] crate. Refer to
21
21
/// [getrandom] documentation for details.
22
22
///
23
+ /// This struct is only available when specifying the crate feature `getrandom`
24
+ /// or `std`. When using the `rand` lib, it is also available as `rand::rngs::OsRng`.
25
+ ///
23
26
/// # Blocking and error handling
24
27
///
25
28
/// It is possible that when used during early boot the first call to `OsRng`
@@ -33,30 +36,17 @@ use rand_core::{CryptoRng, RngCore, Error, impls};
33
36
///
34
37
/// # Usage example
35
38
/// ```
36
- /// use rand::rngs::{StdRng, OsRng};
37
- /// use rand::{RngCore, SeedableRng};
39
+ /// use rand_core::{RngCore, OsRng};
38
40
///
39
41
/// let mut key = [0u8; 16];
40
42
/// OsRng.fill_bytes(&mut key);
41
43
/// let random_u64 = OsRng.next_u64();
42
- ///
43
- /// // OsRng is especially useful for seeding other RNGs (see also from_entropy)
44
- /// let mut rng = StdRng::from_rng(OsRng).unwrap();
45
- /// let _ = rng.next_u32();
46
44
/// ```
47
45
///
48
46
/// [getrandom]: https://crates.io/crates/getrandom
49
47
#[ derive( Clone , Copy , Debug , Default ) ]
50
48
pub struct OsRng ;
51
49
52
- impl OsRng {
53
- /// Create a new `OsRng`.
54
- #[ deprecated( since="0.7.0" , note="replace OsRng::new().unwrap() with just OsRng" ) ]
55
- pub fn new ( ) -> Result < OsRng , Error > {
56
- Ok ( OsRng )
57
- }
58
- }
59
-
60
50
impl CryptoRng for OsRng { }
61
51
62
52
impl RngCore for OsRng {
0 commit comments