Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Tracking Issue for secure random data generation in std #130703

Copy link
Copy link
@joboet

Description

@joboet
Issue body actions

Feature gate: #![feature(random)]

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

Central to this feature is the RandomSource trait inside core::random, which generates random bytes. std also exposes the platform's secure random number generator via the DefaultRandomSource type. There is a Distribution<T> trait for distributions that can sample random values of a specific type, and a random function for convenience to allow things like random(1..=6).

Public API

// core::random

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

pub trait Distribution<T> {
    fn sample(&self, source: &mut (impl RandomSource + ?Sized)) -> T;
}

impl Distribution<bool> for RangeFull { ... }
impl Distribution</* all integer types */> for /* all range types */ { ... }

// std::random (additionally)

pub struct DefaultRandomSource;

impl RandomSource for DefaultRandomSource { ... }

pub fn random<T>(dist: &(impl Distribution<T> + ?Sized)) -> T;

Steps / History

Unresolved Questions

Footnotes

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

elichai, wmstack, bjoernager, barakugav, jhpratt and 16 moreKolsky, zirconium-n and magistauBugenZhaoyoshuawuyts, ctz, ClementNerma, m4rch3n1ng, WyvernIXTL and 9 morebjoernager and KixunilClementNerma, JarvisCraft and wiktor-kPatchMixolydic, clubby789, randomairborne, GnomedDev, Fnige and 7 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.