Go rand.Intn same number/value
问题 Can anyone please tell me why the Go example here: https://tour.golang.org/basics/1 always returns the same value for rand.Intn(10)? 回答1: 2 reasons: You have to initalize the global Source used by rand.Intn() and other functions of the rand package using rand.Seed(). For example: rand.Seed(time.Now().UnixNano()) See possible duplicate of Difficulty with Go Rand package. Quoting from package doc of rand: Top-level functions, such as Float64 and Int, use a default shared Source that produces a