Line data Source code
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 : "math/rand/v2" 9 : "time" 10 : ) 11 : 12 : // NewRand creates a new random number generator seeded with the current time. 13 0 : func NewRand() *rand.Rand { 14 0 : return rand.New(rand.NewPCG(0, uint64(time.Now().UnixNano()))) 15 0 : } 16 : 17 0 : func ensureRand(rng *rand.Rand) *rand.Rand { 18 0 : if rng != nil { 19 0 : return rng 20 0 : } 21 0 : return NewRand() 22 : }