Stdlibrandom
secure
import std::random::secure; · source
SecureRng
type struct SecureRng {
static new() -> SecureRng;
try_fill(&this, dst: Slice<u8>) -> Result<(), RandomError>;
}
import std::random::secure;
mut s: SecureRng = SecureRng::new();
s.fill(key.as_slice());
Because it satisfies RandomSource, the full draw surface above is available. Those defaults panic if the kernel cannot supply entropy — a broken system invariant rather than an expected failure. When you need to handle it, use try_fill, which reports it as EntropyUnavailable.
SecureRng is stateless, so a copy is the same source. The backing call is per target: getrandom on Unix, RtlGenRandom on Windows. Rng::from_os routes through the same portable helper rather than binding the Linux-only symbol directly.
Trait implementations
implement trait RandomSource for struct SecureRng
Its RandomSource impl overrides fill so a bulk request is one kernel call rather than a loop of next_64.