The modern algorithm
/*
-- To shuffle an array a of n elements (indices 0..n-1):
for i from n−1 downto 1 do
j ← random integer such that 0 ≤ j ≤ i
exchange a[j] and a[i]
*/
func shuffle(items[] int) {
i := len(items) - 1
for i >= 1 {
j := rand.Int63n(int64(i + 1))
items[i], items[j] = items[j], items[i]
i--
}
}
/*
-- To shuffle an array a of n elements (indices 0..n-1):
for i from 0 to n−2 do
j ← random integer such that i ≤ j < n
exchange a[i] and a[j]
*/
func shuffle2(items[] int) {
i := 0
n := len(items)
for i <= n - 2 {
j := rand.Int63n(int64(n - i)) + int64(i)
items[i], items[j] = items[j], items[i]
i++
}
}