github.com/aavshr/aws-sdk-go@v1.41.3/internal/sdkrand/locked_source.go (about) 1 package sdkrand 2 3 import ( 4 "math/rand" 5 "sync" 6 "time" 7 ) 8 9 // lockedSource is a thread-safe implementation of rand.Source 10 type lockedSource struct { 11 lk sync.Mutex 12 src rand.Source 13 } 14 15 func (r *lockedSource) Int63() (n int64) { 16 r.lk.Lock() 17 n = r.src.Int63() 18 r.lk.Unlock() 19 return 20 } 21 22 func (r *lockedSource) Seed(seed int64) { 23 r.lk.Lock() 24 r.src.Seed(seed) 25 r.lk.Unlock() 26 } 27 28 // SeededRand is a new RNG using a thread safe implementation of rand.Source 29 var SeededRand = rand.New(&lockedSource{src: rand.NewSource(time.Now().UnixNano())})