Struct DefaultRandomSource

struct DefaultRandomSource

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, 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
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.

Implementations

impl Clone for DefaultRandomSource

fn clone(self: &Self) -> DefaultRandomSource

impl Copy for DefaultRandomSource

impl Debug for DefaultRandomSource

fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result

impl Default for DefaultRandomSource

fn default() -> DefaultRandomSource

impl Freeze for DefaultRandomSource

impl RandomSource for DefaultRandomSource

fn fill_bytes(self: &mut Self, bytes: &mut [u8])

impl RefUnwindSafe for DefaultRandomSource

impl Send for DefaultRandomSource

impl Sync for DefaultRandomSource

impl Unpin for DefaultRandomSource

impl UnwindSafe for DefaultRandomSource

impl<T> Any for DefaultRandomSource

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for DefaultRandomSource

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for DefaultRandomSource

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for DefaultRandomSource

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for DefaultRandomSource

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for DefaultRandomSource

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for DefaultRandomSource

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for DefaultRandomSource

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for DefaultRandomSource

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>