dimanche 23 juillet 2017

How do I Seed random number generator on official Tour of Go?

The official tour of Go gives the following code in the sandbox:

package main

import (
    "fmt"
    "math/rand"
)

func main() {
    fmt.Println("My favorite number is", rand.Intn(10))
}

And this instruction:

Note: the environment in which these programs are executed is deterministic, so each time you run the example program rand.Intn will return the same number. (To see a different number, seed the number generator; see rand.Seed.)

After reading the entry under the official documentation for rand.Seed and reading this answer, I still can't correctly seed the random number generator.

Can someone please demonstrate how the rand.Seed function should be used to seed the random number generator?

Many thanks, Jon




Aucun commentaire:

Enregistrer un commentaire