Skip to content

Commit

Permalink
lock for keygen
Browse files Browse the repository at this point in the history
  • Loading branch information
gunlee01 committed Jan 31, 2021
1 parent db713a0 commit f60fc99
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scouterx/common/util/keygen/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var keygen *KeyGen

// A KeyGen is a source of random numbers
type KeyGen struct {
sync.Mutex
random *rand.Rand
}

Expand All @@ -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() {
Expand Down

0 comments on commit f60fc99

Please sign in to comment.