Skip to content

Conversation

@dhardy
Copy link
Member

@dhardy dhardy commented Oct 21, 2025

  • Added a CHANGELOG.md entry

Summary

Moves OsRng from rand_core to rand.

Removes fns SeedableRng::from_os_rng and try_from_os_rng.

Motivation

This removes the dependency on getrandom, making rand_core dependency-free (unless serde is enabled) and allowing an easier path to stabilisation of rand_core. See #1666.

Details

Removed features std and os_rng from rand_core.

@dhardy dhardy requested a review from newpavlov October 21, 2025 12:57
Comment on lines 40 to 44
/// Using a fresh seed **direct from the OS** is the most secure option:
/// ```
/// # use rand::{SeedableRng, rngs::StdRng};
/// let rng = StdRng::from_os_rng();
/// # use rand::{SeedableRng, rngs::{StdRng, OsRng}};
/// let rng = StdRng::try_from_rng(&mut OsRng).unwrap();
/// # let _: StdRng = rng;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly less ergonomic than before, but affected us very little.

Unknown: how much this impacts other users.

@dhardy dhardy force-pushed the push-putxlzvnyulq branch from 7f48893 to 2a71fe4 Compare October 21, 2025 13:06
@dhardy dhardy mentioned this pull request Oct 21, 2025
6 tasks
@dhardy dhardy requested review from benjamin-lieser and vks October 22, 2025 07:46
@dhardy dhardy mentioned this pull request Oct 22, 2025
1 task
@dhardy dhardy force-pushed the push-putxlzvnyulq branch from bd43aaf to 1d3235c Compare October 22, 2025 08:33
@dhardy dhardy mentioned this pull request Oct 22, 2025
7 tasks
Copy link
Collaborator

@vks vks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reverts a change we did a long time ago. Do you remember why we moved it from rand_os to rand_core in the first place?

@dhardy
Copy link
Member Author

dhardy commented Oct 25, 2025

SeedableRng::from_os_rng requires OsRng. We want to keep SeedableRng in rand_core, so essentially we must choose between:

  1. Do not offer a from_os_rng method (this PR). This works fine for us but there are clearly some users (GH search).
  2. Status quo: rand_core depends on getrandom for from_os_rng.
  3. Add an extension trait SeedableRngExt: SeedableRng in rand and implement from_os_rng there. We could also add from_thread_rng in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants