Commit da28b597 authored by yahtoo's avatar yahtoo Committed by Paladz

Add timestamp as random number generator seed (#1698)

parent fd61058e
......@@ -2,6 +2,7 @@ package netsync
import (
"math/rand"
"time"
log "github.com/sirupsen/logrus"
......@@ -113,7 +114,7 @@ func (sm *SyncManager) txSyncLoop() {
return nil
}
n := rand.Intn(len(pending)) + 1
n := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(pending)) + 1
for _, s := range pending {
if n--; n == 0 {
return s
......
......@@ -12,6 +12,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"github.com/bytom/common"
"github.com/bytom/crypto"
......@@ -424,7 +425,7 @@ func hashAtDistance(a common.Hash, n int) (b common.Hash) {
}
b[pos] = a[pos]&^bit | ^a[pos]&bit // TODO: randomize end bits
for i := pos + 1; i < len(a); i++ {
b[i] = byte(rand.Intn(255))
b[i] = byte(rand.New(rand.NewSource(time.Now().UnixNano())).Intn(255))
}
return b
}
......@@ -539,7 +539,7 @@ func (s *ticketStore) addTicket(localTime AbsTime, pingHash []byte, ticket *tick
if _, ok := s.tickets[topic]; ok {
wait := ticket.regTime[topicIdx] - localTime
rnd := rand.ExpFloat64()
rnd := rand.New(rand.NewSource(time.Now().UnixNano())).ExpFloat64()
if rnd > 10 {
rnd = 10
}
......@@ -752,7 +752,7 @@ func globalRandRead(b []byte) {
val := 0
for n := 0; n < len(b); n++ {
if pos == 0 {
val = rand.Int()
val = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
pos = 7
}
b[n] = byte(val)
......
......@@ -344,7 +344,7 @@ func (w *waitControlLoop) hasMinimumWaitPeriod() bool {
}
func noRegTimeout() time.Duration {
e := rand.ExpFloat64()
e := rand.New(rand.NewSource(time.Now().UnixNano())).ExpFloat64()
if e > 100 {
e = 100
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment