3
3
//! The [`Random`] trait allows generating a random value for a type using a
4
4
//! given [`RandomSource`].
5
5
6
- #[ unstable( feature = "random" , issue = "none " ) ]
6
+ #[ unstable( feature = "random" , issue = "130703 " ) ]
7
7
pub use core:: random:: * ;
8
8
9
9
use crate :: sys:: random as sys;
@@ -15,9 +15,9 @@ use crate::sys::random as sys;
15
15
/// documentation below for the specific guarantees your target provides.
16
16
///
17
17
/// The high quality of randomness provided by this source means it can be quite
18
- /// slow. If you need a large quantity of random numbers and security is not a
19
- /// concern, consider using an alternative random number generator (potentially
20
- /// seeded from this one).
18
+ /// slow on some targets . If you need a large quantity of random numbers and
19
+ /// security is not a concern, consider using an alternative random number
20
+ /// generator (potentially seeded from this one).
21
21
///
22
22
/// # Underlying sources
23
23
///
@@ -26,9 +26,9 @@ use crate::sys::random as sys;
26
26
/// Linux | [`getrandom`] or [`/dev/urandom`] after polling `/dev/random`
27
27
/// Windows | [`ProcessPrng`](https://learn.microsoft.com/en-us/windows/win32/seccng/processprng)
28
28
/// Apple | `CCRandomGenerateBytes`
29
- /// DragonFly | [`arc4random_buf`](https://man.dragonflybsd.org/?command=arc4random§ion=ANY )
29
+ /// DragonFly | [`arc4random_buf`](https://man.dragonflybsd.org/?command=arc4random)
30
30
/// ESP-IDF | [`esp_fill_random`](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html#_CPPv415esp_fill_randomPv6size_t)
31
- /// FreeBSD | [`arc4random_buf`](https://man.freebsd.org/cgi/man.cgi?query=arc4random&apropos=0&sektion=0&manpath=FreeBSD+15.0-CURRENT&arch=default&format=html )
31
+ /// FreeBSD | [`arc4random_buf`](https://man.freebsd.org/cgi/man.cgi?query=arc4random)
32
32
/// Fuchsia | [`cprng_draw`](https://fuchsia.dev/reference/syscalls/cprng_draw)
33
33
/// Haiku | `arc4random_buf`
34
34
/// Illumos | [`arc4random_buf`](https://www.illumos.org/man/3C/arc4random)
@@ -48,15 +48,19 @@ use crate::sys::random as sys;
48
48
/// WASI | [`random_get`](https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-random_getbuf-pointeru8-buf_len-size---result-errno)
49
49
/// ZKVM | `sys_rand`
50
50
///
51
- /// **Disclaimer:** The sources used might change over time.
51
+ /// Note that the sources used might change over time.
52
+ ///
53
+ /// Consult the documentation for the underlying operations on your supported
54
+ /// targets to determine whether they provide any particular desired properties,
55
+ /// such as support for reseeding on VM fork operations.
52
56
///
53
57
/// [`getrandom`]: https://www.man7.org/linux/man-pages/man2/getrandom.2.html
54
58
/// [`/dev/urandom`]: https://www.man7.org/linux/man-pages/man4/random.4.html
55
59
#[ derive( Default , Debug , Clone , Copy ) ]
56
- #[ unstable( feature = "random" , issue = "none " ) ]
60
+ #[ unstable( feature = "random" , issue = "130703 " ) ]
57
61
pub struct DefaultRandomSource ;
58
62
59
- #[ unstable( feature = "random" , issue = "none " ) ]
63
+ #[ unstable( feature = "random" , issue = "130703 " ) ]
60
64
impl RandomSource for DefaultRandomSource {
61
65
fn fill_bytes ( & mut self , bytes : & mut [ u8 ] ) {
62
66
sys:: fill_bytes ( bytes)
@@ -83,7 +87,7 @@ impl RandomSource for DefaultRandomSource {
83
87
///
84
88
/// use std::random::random;
85
89
///
86
- /// let bits = random::<u128> ();
90
+ /// let bits: u128 = random();
87
91
/// let g1 = (bits >> 96) as u32;
88
92
/// let g2 = (bits >> 80) as u16;
89
93
/// let g3 = (0x4000 | (bits >> 64) & 0x0fff) as u16;
@@ -94,6 +98,7 @@ impl RandomSource for DefaultRandomSource {
94
98
/// ```
95
99
///
96
100
/// [version 4/variant 1 UUID]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)
101
+ #[ unstable( feature = "random" , issue = "130703" ) ]
97
102
pub fn random < T : Random > ( ) -> T {
98
103
T :: random ( & mut DefaultRandomSource )
99
104
}
0 commit comments