sing/common/random/seed_go119.go
2024-11-05 18:43:04 +08:00

24 lines
360 B
Go

//go:build !go1.20
package random
import (
"crypto/rand"
"encoding/binary"
mRand "math/rand"
"sync"
"github.com/sagernet/sing/common"
)
var initSeedOnce sync.Once
func InitializeSeed() {
initSeedOnce.Do(initializeSeed)
}
func initializeSeed() {
var seed int64
common.Must(binary.Read(rand.Reader, binary.LittleEndian, &seed))
mRand.Seed(seed)
}