Skip to content

Commit

Permalink
rand: generate a new seed each time a new ID is required
Browse files Browse the repository at this point in the history
To avoid generating the same container ID or name for two
different tests, the random seed should be generated when
the random string is required.

fixes kata-containers#1304

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Mar 14, 2019
1 parent 256a00e commit 15541e3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const letters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

const lettersMask = 63

var randSrc = rand.NewSource(time.Now().UnixNano())

// RandID returns a random string
func RandID(n int) string {
randSrc := rand.NewSource(time.Now().UnixNano())
b := make([]byte, n)
for i := 0; i < n; {
if j := int(randSrc.Int63() & lettersMask); j < len(letters) {
Expand Down

0 comments on commit 15541e3

Please sign in to comment.