Rename NewRng::new → FromEntropy::from_entropy#375
Conversation
|
I still think the
If we decide to change anything here, |
|
But always good to try to do something with critique, and see if we can get something better. So 👍 for the PR. |
|
What do you think of having two methods in |
|
I was thinking about that; there's some sense to it but I'm not sure; it's not a lot easier than writing |
No, it is not for us. But it takes two imports ( I don't care all that strongly. But I believe such a convenience method would put both source on a more even foot.
That idea is new to me. What would be the reason for doing something like that? |
|
So maybe as follows: pub trait NewRng {
// both methods panic on error since this trait is pure convenience:
fn from_entropy() -> Self;
fn from_thread_rng() -> Self;
}Reasoning:
|
|
What's the difference between the two methods? |
|
One uses |
|
I prefer something with It sounds more approachable, and I have my doubts whether "construct an RNG from entropy" is a correct expression. |
|
`from_entropy` is consistent with `EntropyRng`. `fresh` is very unspecific
IMHO. What about `from_os`?
…On Sat, Apr 7, 2018, 21:13 Paul Dicker ***@***.***> wrote:
I prefer something with fresh in the name, as you suggested in the first
comment, over from_entropy.
It sounds more approachable, and I have my doubts whether "construct an
RNG from entropy" is a correct expression.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#375 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACCtP9DJFGgVBxi1-dTMByOojrKxuEUks5tmQ_3gaJpZM4TIhqb>
.
|
|
If we go with
Contrary to what I said earlier, the redundant name So I'm tempted to merge this PR as is, or possibly with the |
👍 for merging as is.
On an unrelated note, does it make sense to rename |
pitdicker
left a comment
There was a problem hiding this comment.
I am not the greatest fan of this renaming, but feel free to merge. (Maybe do something with my one comment)
On thing that just now occured to me: The release note and changelog should mention that it is no longer possible to call StdRng::new(), and that FromEntropy::from_entropy is the replacement.
| /// use rand::{thread_rng, Rng}; | ||
| /// use rand::distributions::Exp1; | ||
| /// | ||
| /// let val: f64 = SmallRng::new().sample(Exp1); |
There was a problem hiding this comment.
Using SmallRng in these examples seems like something nice to preserve. It does not matter much, but I expect this code to be mostly used in combination with the simpler non-cryptographic RNGs. So it would fit more with the way users use it.
There was a problem hiding this comment.
Good point, I missed this change. I completely agree.
Implement #360.
I wanted to try this, but personally I'm not so keen.
Advantage:
SmallRng::from_entropy()does thanSmallRng::new()Disadvantages:
OsRng::new()?from_entropyis a little longAlternatives:
SmallRng::from_rng(entropy_rng())?— but this is longer and has error handlingNewRng::new_fresh()— just a rename