We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7af0839 commit fb01ad2Copy full SHA for fb01ad2
src/math/rand/rand.go
@@ -148,6 +148,11 @@ func (r *Rand) Float32() float32 {
148
// Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n).
149
func (r *Rand) Perm(n int) []int {
150
m := make([]int, n)
151
+ // In the following loop, the iteration when i=0 always swaps m[0] with m[0].
152
+ // A change to remove this useless iteration is to assign 1 to i in the init
153
+ // statement. But Perm also effects r. Making this change will affect
154
+ // the final state of r. So this change can't be made for compatibility
155
+ // reasons for Go 1.
156
for i := 0; i < n; i++ {
157
j := r.Intn(i + 1)
158
m[i] = m[j]
0 commit comments