Skip to content

Where does OsRng belong? #1675

@dhardy

Description

@dhardy

Originally posted by @Bluefinger in #1643:

As a third party using rand_core/rand for other projects, I do think something like OsRng belongs to getrandom, since it is exactly the purview of getrandom to provide OS entropy sources. To my brain, the puzzle piece just fits. That said, keeping getrandom lean is another consideration (if seeking to avoid adding features), so an os-rng crate probably would be a good alternative. Being able to depend on smaller, more focused crates is just nicer and preferable, else I'll probably end up rigging up my own OsRng if it means not needing to depend directly on rand if I can help it. However, that might not be too big of a concern, because the main crate I maintain is for a bevy plugin, and bevy already depends on rand anyway...

So all in all, might not actually matter either way. Just yeah, I like smaller crates where possible, but I am not going to lose sleep over it 😄

Reply by @newpavlov:

How about introducing an os-rng crate (or with some other name) and add to it not only OsRng (which I would prefer to rename to SysRng and make OsRng a deprecated type alias), but also ThreadRng behind a crate feature?

It would not only allow us to use ThreadRng without the rest of rand, but also on some platforms OsRng already uses a user-space PRNG (e.g. Windows) and it would be more efficient to use it directly for ThreadRng.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions