*Here's the doc for shuffle in math/random*:

func Shuffle(n int <https://golang.org/pkg/builtin/#int>, swap func(i, j int 
<https://golang.org/pkg/builtin/#int>))

Shuffle pseudo-randomizes the order of elements using the default Source. n 
is the number of elements. Shuffle panics if n < 0. swap swaps the elements 
with indexes i and j. 

*And here's the example*:

package main

import (
    "fmt"
    "math/rand"
    "strings"
)

func main() {
    words := strings.Fields("ink runs from the corners of my mouth")
    rand.Shuffle(len(words), func(i, j int) {
        words[i], words[j] = words[j], words[i]
    })
    fmt.Println(words)

}

*Why can't I understand a word of it?*
(This is not atypical, by the way - and not just for go - so if someone can 
educate me, I might suddenly start prospering in the software game)

Issues (for me):

   - Shuffle doesn't seem to swap anything (the thing you want shuffled 
   isn't even an argument)
   - As I read it the example, it should only swap two words (index i and 
   j) but it seems to shuffle the everything
   - What's this bloody "func" thing???
   - Why doesn't "swap" appear in the example?

Yours sincerely,
*Confused*

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to