File: random.go

package info (click to toggle)
golang-github-tombuildsstuff-giovanni 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,908 kB
  • sloc: makefile: 3
file content (27 lines) | stat: -rw-r--r-- 447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package testhelpers

import (
	"math/rand"
	"time"
)

func RandomInt() int {
	reseed()
	return rand.New(rand.NewSource(time.Now().UnixNano())).Int()
}

func RandomString() string {
	size := 5
	charSet := "abcdefghijklmnopqrstuvwxyz0123456789"

	reseed()
	result := make([]byte, size)
	for i := 0; i < size; i++ {
		result[i] = charSet[rand.Intn(len(charSet))]
	}
	return string(result)
}

func reseed() {
	rand.Seed(time.Now().UTC().UnixNano())
}