diff options
| author | Jingguo Yao <yaojingguo@gmail.com> | 2015-11-12 21:59:30 +0800 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2015-11-15 08:21:29 +0000 |
| commit | fb01ad21c2bdc12e415967f1266bbf86d90956bc (patch) | |
| tree | 04027ec48f006d475f553dbade4e04458f356d23 /src | |
| parent | 7af0839e11378b153feaa9570aeb2cdcdc06b75f (diff) | |
| download | go-fb01ad21c2bdc12e415967f1266bbf86d90956bc.tar.xz | |
math/rand: add a comment for the i=0 iteration
Fixes #13215
Change-Id: I126117d42e7c1e69cbc7fad0760e225b03ed15bd
Reviewed-on: https://go-review.googlesource.com/16852
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/math/rand/rand.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/math/rand/rand.go b/src/math/rand/rand.go index 075b0e580e..925d381cb2 100644 --- a/src/math/rand/rand.go +++ b/src/math/rand/rand.go @@ -148,6 +148,11 @@ func (r *Rand) Float32() float32 { // Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n). func (r *Rand) Perm(n int) []int { m := make([]int, n) + // In the following loop, the iteration when i=0 always swaps m[0] with m[0]. + // A change to remove this useless iteration is to assign 1 to i in the init + // statement. But Perm also effects r. Making this change will affect + // the final state of r. So this change can't be made for compatibility + // reasons for Go 1. for i := 0; i < n; i++ { j := r.Intn(i + 1) m[i] = m[j] |
