diff options
author | Bhasker Hariharan <bhaskerh@google.com> | 2020-08-20 11:05:37 -0700 |
---|---|---|
committer | Andrei Vagin <avagin@gmail.com> | 2020-09-09 17:53:10 -0700 |
commit | 78cc2396bb1b3d89c4606fa95a77b151bb529c96 (patch) | |
tree | 28992de4cfbfe1477cfcac7e87857fd93ada4996 /pkg/test | |
parent | c0ae8604b524b80d77a1596fded05ef09d1f76fd (diff) |
Use a explicit random src for RandomID.
PiperOrigin-RevId: 327659759
Diffstat (limited to 'pkg/test')
-rw-r--r-- | pkg/test/testutil/testutil.go | 5 |
1 files changed, 4 insertions, 1 deletions
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 != "" { |