-
Notifications
You must be signed in to change notification settings - Fork 18k
a iteration can be saved for "func (r *Rand) Perm(n int) []int" #13215
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
Indeed. Unfortunately, this is tricky. Perm also side-effects r, and making this change will affect the final state of r. I don't think we can do that for compatibility reasons. Too bad Intn(1) wasn't originally coded to do the n==1 shortcut. Care to make a patch? |
I think preserving the call to rand.Intn will negate any speed advantage of
the saved iteration.
Perhaps we should just add a note that we need to preserve the rand state
here.
|
Yeah, it's not a big win. |
@randall77, so the conclusion is for me to make a patch which adds a comment, right? |
Yes, sounds good. |
Yes.
|
A patch is created. |
CL https://golang.org/cl/16803 mentions this issue. |
CL https://golang.org/cl/16852 mentions this issue. |
In
src/math/rand/rand.go
, there is the following code:i
can start from1
instead of0
since the iteration fori=0
always swapm[0]
withm[0]
. A fix is to changei := 0
toi := 1
.The text was updated successfully, but these errors were encountered: