-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Random number generators should not implement Copy #20170
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
Comments
I'd agree that they probably shouldn't be |
nagisa
added a commit
to nagisa/rust
that referenced
this issue
Dec 24, 2014
Remove derivations of `Copy` trait from `ChaChaRng`, `IsaacRng`, `Isaac64Rng` and `StdRng` and implement the `Clone` trait instead. Copying is an implicit operation and the copy shares its internal state with the original generator. This means the the two generators will yield exactly the same sequence of values. This behaviour is considerably easy to trigger by, for example, passing the generator by value to a function. `Clone` trait, on the other hand, does no implicit copying. The user will only be able to either move the generator or ask for a copy explicitly, via the `clone` method. The only downside to this patch is the fact that the implementations of `Clone::clone` methods do not optimise down to a single memcpy, like the derived `Copy` implementations did. Although the `Copy` implementations of these random number generators are suspected to not be used much, this is a [breaking-change]. Fixes rust-lang#20170.
NB. This is not a question of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently there’s a few random number generators that implement
Copy
:All of these random number generators have a bad property of also copying their seed/internal data implicitly, rather than splitting their seed between original and copied generators. This means that Rng in question will start generating the same sequence values when generator is passed by value.
These generators should not implement Copy (implicit) and implement Clone (explicit) instead in case copying generators is intended (which is almost never a case), like
XorShiftRng
does. Maybe I just missed the use-case ofCopy
able PRNGs?The text was updated successfully, but these errors were encountered: