Tracking Issue for secure random data generation in std · Issue #130703 · rust-lang/rust (original) (raw)

Feature gate: #![feature(random)]

This is a tracking issue for secure random data generation support in std.

Central to this feature are the Random and RandomSource traits inside core::random. The Random trait defines a method to create a new random value of the implementing type from random bytes generated by a RandomSource. std also exposes the platform's secure random number generator via the DefaultRandomSource type which can be conveniently access via the random::random function.

Public API

// core::random

pub trait RandomSource { fn fill_bytes(&mut self, bytes: &mut [u8]); }

pub trait Random { fn random(source: &mut (impl RandomSource + ?Sized)) -> Self; }

impl Random for bool { ... } impl Random for /* all integer types */ { ... }

// std::random (additionally)

pub struct DefaultRandomSource;

impl RandomSource for DefaultRandomSource { ... }

pub fn random<T: Random>() -> T { ... }

Steps / History

Unresolved Questions

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html