Go's math/rand package provides pseudorandom number generation
package main import ( "fmt" "math/rand" ) func main() { fmt.Print(rand.Intn(100), ",") fmt.Println() fmt.Println(rand.Float64()) fmt.Println((rand.Float64()*5)+5, ",") s1 := rand.NewSource(42) r1 := rand.New(s1) fmt.Println(r1.Intn(100)) s2 := rand.NewSource(42) r2 := rand.New(s2) fmt.Println(r2.Intn(100)) }
81, 0.9405090880450124 8.322800266092452 , 5 5
总结 :
1 : ....
有疑问加站长微信联系(非本文作者)