-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove weak_rng #20773
Remove weak_rng #20773
Conversation
I'd personally prefer an alternative where we keep weak_rng, but encapsulate the return type: pub fn weak_rng() -> WeakRng { ... }
pub struct WeakRng(XorShiftRng);
impl Rng for WeakRng { ... } |
That’s what I originally suggested. I’m fine either way, but as always, feedback is scarce without PRs 😉 |
@sfackler We can always add that in later, I'm not really sure how much sense it makes to have a plethora different RNG types, several of which are just renamed/slightly tweaked versions of others. I'd like the module to feel less... sprawling. It seems like this would be better suited to an external library which can then choose the internal |
(That said, I'm very willing to be convince otherwise, so won't approve for now. Thanks for the PR, @nagisa.) |
@@ -1585,7 +1585,7 @@ mod test_map { | |||
use super::Entry::{Occupied, Vacant}; | |||
use iter::{range_inclusive, range_step_inclusive, repeat}; | |||
use cell::RefCell; | |||
use rand::{weak_rng, Rng}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be better to change these to XorShiftRng
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As these are used for tests and XorShiftRng
needs to be seeded manually now, I think preserved noise-to-signal ratio is much more valuable than those few µs we’d save by not using thread_rng.
strconv
benchmarks are another story, though. Will update these tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get a randomly seeded one with rand::random::<XorShiftRng>()
, btw.
Ah indeed, |
So I'm of the opinion that we want functions like |
We have the "obvious" name I 100% agree we don't need all of those types. I'm actually thinking that we switch to That said, there's going to be a close analysis of (BTW, @nagisa, could you amend the commit message to include the suggested migration path, |
a0aded2
to
90f64b1
Compare
@@ -22,7 +22,7 @@ pub fn insert_rand_n<M, I, R>(n: uint, | |||
R: FnMut(&mut M, uint), | |||
{ | |||
// setup | |||
let mut rng = rand::weak_rng(); | |||
let mut rng : XorShiftRng = rand::random(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standard code style requests that there be no space before the colon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
90f64b1
to
118fb92
Compare
re-r? @huonw |
Documentation for the function claims it will return the fastest algorithm available in Rust, but since its return type is hardcoded to XorShiftRng, it would be an impossible [breaking-change], when, or if, a faster Rng is added to Rust. [breaking-change], since this removes public API. Uses of `weak_rng` function can be replaced with `random::<XorShiftRng>()` to achieve almost the same behaviour. Fixes rust-lang#20484
118fb92
to
c1b98aa
Compare
This needs a rebase. |
I will rebase after the relevant RFC gets accepted because it conflicts often. |
(The RFC was closed in favour of moving |
Documentation for the function claims it will return the fastest algorithm
available in Rust, but since its return type is hardcoded to XorShiftRng, it
would be an impossible [breaking-change], when, or if, a faster Rng is added to
Rust.
[breaking-change], since this removes public API.
Fixes #20484
r? @huonw for a rollup post 1.0α.