From 2fd782eee89402f10b5746f281077b10765b31c7 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 23 Aug 2019 18:19:07 +0300 Subject: [PATCH] util: drop RandUint32() I don't see anything useful in it, all the current users of it should just use plain rand.Uint32() not limiting its output in any way. --- pkg/network/helper_test.go | 3 ++- pkg/network/server.go | 7 ++++++- pkg/util/random.go | 16 ---------------- 3 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 pkg/util/random.go diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index 9bb6803b1..bdf6a9c83 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -1,6 +1,7 @@ package network import ( + "math/rand" "testing" "time" @@ -149,7 +150,7 @@ func newTestServer() *Server { chain: testChain{}, transport: localTransport{}, discovery: testDiscovery{}, - id: util.RandUint32(1000000, 9999999), + id: rand.Uint32(), quit: make(chan struct{}), register: make(chan Peer), unregister: make(chan peerDrop), diff --git a/pkg/network/server.go b/pkg/network/server.go index f6e9f4416..d6e260956 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -3,6 +3,7 @@ package network import ( "errors" "fmt" + "math/rand" "sync" "time" @@ -61,7 +62,7 @@ func NewServer(config ServerConfig, chain core.Blockchainer) *Server { s := &Server{ ServerConfig: config, chain: chain, - id: util.RandUint32(1000000, 9999999), + id: rand.Uint32(), quit: make(chan struct{}), register: make(chan Peer), unregister: make(chan peerDrop), @@ -349,3 +350,7 @@ func (s *Server) RelayDirectly(p Peer, inv *payload.Inventory) { p.WriteMsg(NewMessage(s.Net, CMDInv, inv)) } + +func init() { + rand.Seed(time.Now().UTC().UnixNano()) +} diff --git a/pkg/util/random.go b/pkg/util/random.go deleted file mode 100644 index 0ea02d4d9..000000000 --- a/pkg/util/random.go +++ /dev/null @@ -1,16 +0,0 @@ -package util - -import ( - "math/rand" - "time" -) - -// RandUint32 return a random number between min and max. -func RandUint32(min, max int) uint32 { - n := min + rand.Intn(max-min) - return uint32(n) -} - -func init() { - rand.Seed(time.Now().UTC().UnixNano()) -}