golang源码学习之math/rand
本文不对具体的实现作分析,而是为了解决下面两个问题。 相同种子,为什么每次运行的结果一样? 不同的种子, 为什么每次运行的结果有可能一样? 从下面两句代码开始分析吧 rand.Seed(10) rand.Int() // math/rand/rand.go func Seed(seed int64) { globalRand.Seed(seed) } // globalRand 全局变量 var globalRand = New(&lockedSource{src: NewSource(1).(Source64)}) func NewSource(seed int64) Source { var rng rngSource //最终Seed的是 rngSource rng.Seed(seed...阅读全文