pub struct SystemRng;random #130703)Expand description
The system random number generator.
This asks the system for random data suitable for cryptographic purposes such as key generation. If security is a concern, consult the platform documentation below for the specific guarantees your target provides.
The high quality of randomness provided by this source means it can be quite slow on some targets. If you need a large quantity of random numbers and security is not a concern, consider using an alternative random number generator (potentially seeded from this one).
If you need to fill a buffer with random bytes, use SystemRng.fill_bytes(&mut buf).
§Underlying sources
| Platform | Source |
|---|---|
| Linux | getrandom or /dev/urandom after polling /dev/random |
| Windows | ProcessPrng |
| Apple | CCRandomGenerateBytes |
| DragonFly | arc4random_buf |
| ESP-IDF | esp_fill_random |
| FreeBSD | arc4random_buf |
| Fuchsia | cprng_draw |
| Haiku | arc4random_buf |
| Illumos | arc4random_buf |
| NetBSD | arc4random_buf |
| OpenBSD | arc4random_buf |
| Solaris | arc4random_buf |
| Vita | arc4random_buf |
| Hermit | read_entropy |
| Horizon, Cygwin | getrandom |
| AIX, Hurd, L4Re, QNX | /dev/urandom |
| Redox | /scheme/rand |
| RTEMS | arc4random_buf |
| SGX | rdrand |
| SOLID | SOLID_RNG_SampleRandomBytes |
| TEEOS | TEE_GenerateRandom |
| UEFI | EFI_RNG_PROTOCOL |
| VxWorks | randABytes after waiting for randSecure to become ready |
| WASIp1 | random_get |
| WASIp2 | get-random-bytes |
| WASIp3 | get-random-bytes |
| ZKVM | sys_rand |
Note that the sources used might change over time.
Consult the documentation for the underlying operations on your supported targets to determine whether they provide any particular desired properties, such as support for reseeding on VM fork operations.
Trait Implementations§
impl Copy for SystemRng
impl TrivialClone for SystemRng
Auto Trait Implementations§
impl Freeze for SystemRng
impl RefUnwindSafe for SystemRng
impl Send for SystemRng
impl Sync for SystemRng
impl Unpin for SystemRng
impl UnsafeUnpin for SystemRng
impl UnwindSafe for SystemRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Printable for T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more