github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/internal/randvar/rand.go (about) 1 // Copyright 2019 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package randvar 6 7 import ( 8 "time" 9 10 "golang.org/x/exp/rand" 11 ) 12 13 // NewRand creates a new random number generator seeded with the current time. 14 func NewRand() *rand.Rand { 15 return rand.New(rand.NewSource(uint64(time.Now().UnixNano()))) 16 } 17 18 func ensureRand(rng *rand.Rand) *rand.Rand { 19 if rng != nil { 20 return rng 21 } 22 return NewRand() 23 }