Use a better seed for a rand generator

This was causing some test to flap.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2021-08-26 15:16:22 -06:00
parent 56da097b38
commit 4076abfd57

View File

@@ -18,6 +18,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"hash/maphash"
"io/ioutil"
"math"
"math/rand"
@@ -2060,9 +2061,6 @@ func (a *Account) processServiceImportResponse(sub *subscription, c *client, _ *
// Lock should not be held.
func (a *Account) createRespWildcard() []byte {
a.mu.Lock()
if a.prand == nil {
a.prand = rand.New(rand.NewSource(time.Now().UnixNano()))
}
var b = [baseServerLen]byte{'_', 'R', '_', '.'}
rn := a.prand.Uint64()
for i, l := replyPrefixLen, rn; i < len(b); i++ {
@@ -2095,7 +2093,9 @@ func (a *Account) newServiceReply(tracking bool) []byte {
a.mu.Lock()
s, replyPre := a.srv, a.siReply
if a.prand == nil {
a.prand = rand.New(rand.NewSource(time.Now().UnixNano()))
var h maphash.Hash
h.WriteString(nuid.Next())
a.prand = rand.New(rand.NewSource(int64(h.Sum64())))
}
rn := a.prand.Uint64()
a.mu.Unlock()