Skip to content

Conversation

@tarcieri
Copy link
Contributor

@tarcieri tarcieri commented Nov 5, 2025

Summary

Adds methods for seeding SeedableRngs as replacements for the trait methods SeedableRng::{from_os_rng, try_from_os_rng} which were removed in #1674.

Motivation

This is functionality that was otherwise lost migrating OsRng out of rand_core.

Details

Since OsRng is no longer in rand_core which defines the trait, we have to reverse the relationship and place the methods onto OsRng instead.

Adds methods for seeding `SeedableRng`s as replacements for the
trait methods `SeedableRng::{from_os_rng, try_from_os_rng}` which were
removed in rust-random#1674.
@newpavlov
Copy link
Member

newpavlov commented Nov 5, 2025

I think MyRng::try_from_rng(&mut OsRng) and MyRng::from_rng(&mut UnwrapOsRng) already work good enough for this.

@tarcieri tarcieri closed this Nov 6, 2025
@dhardy
Copy link
Member

dhardy commented Nov 6, 2025

Yes; this doesn't add much.

An extension trait providing the original from_os_rng() method(s) would however:

  • be near backwards compatible (requiring only an import)
  • not require referencing both MyRng (whatever that is) and OsRng at the same time when seeding

For seeding a single RNG this is still not sufficient motivation, but for many uses it might be. (Or we could define such a trait in that benchmark. Still blocked by actually having access to OsRng there though.)

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