diff --git a/scouterx/common/util/keygen/keygen.go b/scouterx/common/util/keygen/keygen.go index 3b72a6a..be95773 100644 --- a/scouterx/common/util/keygen/keygen.go +++ b/scouterx/common/util/keygen/keygen.go @@ -13,6 +13,7 @@ var keygen *KeyGen // A KeyGen is a source of random numbers type KeyGen struct { + sync.Mutex random *rand.Rand } @@ -29,7 +30,10 @@ func getInstance() *KeyGen { // Next returns a non-negative pseudo-random 63-bit integer func Next() int64 { - return keygen.random.Int63() + keygen.Lock() + key := keygen.random.Int63() + keygen.Unlock() + return key } func init() {