In go docs there is a shuffle example (link)
I've added some output to it as follows:
package main
import (
"fmt"
"math/rand"
"strings"
)
func main() {
words := strings.Fields("ink runs from the corners of my mouth")
fmt.Println(words)
rand.Shuffle(len(words), func(i, j int) {
fmt.Println("Before:", i, j, words[i])
words[i], words[j] = words[j], words[i]
fmt.Println("After:", i, j, words[i])
})
fmt.Println(words)
}
What I would like to understand is the line that has:
words[i], words[j] = words[j], words[i]
And specifically why the output before and after that statement is different. How is this evaluated? Thanks.