default math.rand.source is thread save while rand.new source is not
Default math rand.Source is thread save while rand.New is not
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
seed := time.Now().UnixNano()
rand.Seed(seed)
fmt.Println(rand.Int63())
}package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
seed := time.Now().UnixNano()
r := rand.New(rand.NewSource(seed))
fmt.Println(r.Int63())
}Last updated