π Initialize random seed in Golang.
import (
"math/rand"
"moul.io/srand"
)
func init() {
rand.Seed(srand.MustSecure())
}Alternative seeds
// simple seed initializer
rand.Seed(srand.Fast())
// thread-safe simple seed initializer
go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }()
go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }()
// simple seed initializer overridable by the $SRAND env var
rand.Seed(srand.Overridable("SRAND"))
// cryptographically secure initializer
rand.Seed(srand.MustSecure())$ go get -u moul.io/srandΒ© 2019-2021 Manfred Touron
Licensed under the Apache License, Version 2.0 (LICENSE-APACHE) or the MIT license (LICENSE-MIT), at your option. See the COPYRIGHT file for more details.
SPDX-License-Identifier: (Apache-2.0 OR MIT)