github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/random/seed_go119.go (about)

     1  //go:build !go1.20
     2  
     3  package random
     4  
     5  import (
     6  	"crypto/rand"
     7  	"encoding/binary"
     8  	mRand "math/rand"
     9  	"sync"
    10  
    11  	"github.com/sagernet/sing/common"
    12  )
    13  
    14  var initSeedOnce sync.Once
    15  
    16  func InitializeSeed() {
    17  	initSeedOnce.Do(initializeSeed)
    18  }
    19  
    20  func initializeSeed() {
    21  	var seed int64
    22  	common.Must(binary.Read(rand.Reader, binary.LittleEndian, &seed))
    23  	//goland:noinspection GoDeprecation
    24  	mRand.Seed(seed)
    25  }