From 710adf23cd151558af718e1a8a02f2abe1059d82 Mon Sep 17 00:00:00 2001 From: Bhasker Hariharan Date: Thu, 20 Aug 2020 11:05:37 -0700 Subject: [PATCH] Use a explicit random src for RandomID. PiperOrigin-RevId: 327659759 --- pkg/test/testutil/testutil.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/test/testutil/testutil.go b/pkg/test/testutil/testutil.go index 3cb6c6814..42d79f5c2 100644 --- a/pkg/test/testutil/testutil.go +++ b/pkg/test/testutil/testutil.go @@ -243,12 +243,15 @@ func writeSpec(dir string, spec *specs.Spec) error { return ioutil.WriteFile(filepath.Join(dir, "config.json"), b, 0755) } +// idRandomSrc is a pseudo random generator used to in RandomID. +var idRandomSrc = rand.New(rand.NewSource(time.Now().UnixNano())) + // RandomID returns 20 random bytes following the given prefix. func RandomID(prefix string) string { // Read 20 random bytes. b := make([]byte, 20) // "[Read] always returns len(p) and a nil error." --godoc - if _, err := rand.Read(b); err != nil { + if _, err := idRandomSrc.Read(b); err != nil { panic("rand.Read failed: " + err.Error()) } if prefix != "" {