pub struct DefaultRandomSource;
random
)std
only.Expand description
The default random source.
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).
§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 | getrandom shim |
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 |
WASI | random_get |
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§
Source§impl Clone for DefaultRandomSource
impl Clone for DefaultRandomSource
Source§fn clone(&self) -> DefaultRandomSource
fn clone(&self) -> DefaultRandomSource
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DefaultRandomSource
impl Debug for DefaultRandomSource
Source§impl Default for DefaultRandomSource
impl Default for DefaultRandomSource
Source§fn default() -> DefaultRandomSource
fn default() -> DefaultRandomSource
Source§impl RandomSource for DefaultRandomSource
impl RandomSource for DefaultRandomSource
Source§fn fill_bytes(&mut self, bytes: &mut [u8])
fn fill_bytes(&mut self, bytes: &mut [u8])
random
)bytes
with random bytes.impl Copy for DefaultRandomSource
Auto Trait Implementations§
impl Freeze for DefaultRandomSource
impl RefUnwindSafe for DefaultRandomSource
impl Send for DefaultRandomSource
impl Sync for DefaultRandomSource
impl Unpin for DefaultRandomSource
impl UnwindSafe for DefaultRandomSource
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more