-
-
Notifications
You must be signed in to change notification settings - Fork 486
Description
This has come up many times already, so quick summary:
- move
Rng,SeedableRng,Error, and some related code to a new crate,rand-core - move some helper code for implementing
Rng(implsandlemodules) torand-core - export all but the helper code in
randtoo
Do we want to do this?
Note: this has already been tested.
Also note: rand already supports no_std; we don't need rand-core for that!
I think it's time we tried to answer this question. I already know some people would like to see this, but I'm less clear of all the reasons. I know @burdges doesn't, because it divides related logic between two different crates, and is mostly unnecessary.
For:
- fairly clean separation; we can put backend docs in
rand-coreand user docs inrand - enables us to move PRNG implementations into sub-crates, and use code from there (see below)
- enables some other crate tricks, e.g. allowing users to replace
OsRng(see below) - less code to review for crates only needing
rand-core
Against:
- doing this requires Add trait SampleRng: Rng and related doc #244 (or something very similar) — contentious but not a big deal
- this might restrict specialisation implementations — no currently known issues
- code and documentation gets split between two crates (though this is also a potential advantage)
PRNG sub-crates: we can for example move XorShiftRng to a rand-small crate, which depends on the rand-core, and have rand expose XorShiftRng as WeakRng. If we tried to do this without a separate rand-core there would be a cyclic dependency rand → rand-small → rand, so we might have to copy the PRNG code.
User-replaceable OsRng: @pitdicker mentioned this somewhere: move OsRng to a sub-crate, and allow users building a binary on a platform not supported by our OsRng to replace our rand-os crate with their own implementation. It is not practical for us to provide an OS entropy source in all cases, e.g. WASM and embedded platforms, and this would allow users to keep thread_rng etc.