github.com/rosedblabs/rosedb/v2@v2.3.7-0.20240423093736-a89ea823e5b9/utils/rand_kv.go (about) 1 package utils 2 3 import ( 4 "fmt" 5 "math/rand" 6 "sync" 7 "time" 8 ) 9 10 var ( 11 lock = sync.Mutex{} 12 randStr = rand.New(rand.NewSource(time.Now().Unix())) 13 letters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") 14 ) 15 16 // GetTestKey get formated key, for test only 17 func GetTestKey(i int) []byte { 18 return []byte(fmt.Sprintf("rosedb-test-key-%09d", i)) 19 } 20 21 // RandomValue generate random value, for test only 22 func RandomValue(n int) []byte { 23 b := make([]byte, n) 24 for i := range b { 25 lock.Lock() 26 b[i] = letters[randStr.Intn(len(letters))] 27 lock.Unlock() 28 } 29 return []byte("rosedb-test-value-" + string(b)) 30 }