Add initialize seed func

This commit is contained in:
世界 2022-07-01 16:46:54 +08:00
parent e85528b42f
commit 2a0502dd66
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -1,8 +1,10 @@
package random
import (
"crypto/rand"
"encoding/binary"
"io"
mRand "math/rand"
"sync"
"github.com/sagernet/sing/common"
@ -13,6 +15,18 @@ const (
rngMask = rngMax - 1
)
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)
}
type Source struct {
io.Reader
}