Skip to content

Commit 1c870df

Browse files
committed
implement funcs to generate N random kv pairs for testing purposes
1 parent 0535dba commit 1c870df

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

utils/kv_gen.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package utils
2+
3+
import (
4+
"math/rand"
5+
"time"
6+
)
7+
8+
func GenerateRandomEntry(store map[string]string) {
9+
// Generate a random string for the key
10+
key := generateRandomString(10)
11+
12+
// Generate a random color from a predefined list
13+
colors := []string{"red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "black", "white"}
14+
color := colors[rand.Intn(len(colors))]
15+
16+
// Store the key-value pair in the map
17+
store[key] = color
18+
}
19+
20+
func generateRandomString(length int) string {
21+
rand.Seed(time.Now().UnixNano())
22+
chars := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
23+
24+
b := make([]rune, length)
25+
for i := range b {
26+
b[i] = chars[rand.Intn(len(chars))]
27+
28+
}
29+
return string(b)
30+
}

0 commit comments

Comments
 (0)