2 reasons:
-
You have to initalize the global
Sourceused byrand.Intn()and other functions of therandpackage usingrand.Seed(). For example:rand.Seed(time.Now().UnixNano())See possible duplicate of Difficulty with Go Rand package.
Quoting from package doc ofrand:Top-level functions, such as Float64 and Int, use a default shared Source that produces a deterministic sequence of values each time a program is run. Use the Seed function to initialize the default Source if different behavior is required for each run.
-
The Tour runs examples on the Go Playground which caches its output.
See details at Why does count++ (instead of count = count + 1) change the way the map is returned in Golang.