Skip to content

Commit

Permalink
[FAB-8427] Seed rand only once
Browse files Browse the repository at this point in the history
Change-Id: I0cfb0d276ac6b88de373db40ac94ac824e6af352
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Feb 21, 2018
1 parent 1147266 commit 20ce0d3
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 12 deletions.
4 changes: 0 additions & 4 deletions pkg/fabric-client/txn/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (

var logger = logging.NewLogger("fabric_sdk_go")

func init() {
rand.Seed(time.Now().UnixNano())
}

// CCProposalType reflects transitions in the chaincode lifecycle
type CCProposalType int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package pgresolver

import (
"math/rand"
"time"
)

type randomLBP struct {
Expand All @@ -28,7 +27,6 @@ func (lbp *randomLBP) Choose(peerGroups []PeerGroup) PeerGroup {
return NewPeerGroup()
}

rand.Seed(int64(time.Now().Nanosecond()))
index := rand.Intn(len(peerGroups))

logger.Debugf("randomLBP - Choosing index %d\n", index)
Expand All @@ -52,7 +50,6 @@ func (lbp *roundRobinLBP) Choose(peerGroups []PeerGroup) PeerGroup {
}

if lbp.index == -1 {
rand.Seed(int64(time.Now().Nanosecond()))
lbp.index = rand.Intn(len(peerGroups))
} else {
lbp.index++
Expand Down
6 changes: 6 additions & 0 deletions pkg/fabsdk/fabsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ SPDX-License-Identifier: Apache-2.0
package fabsdk

import (
"math/rand"
"time"

"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
"github.com/hyperledger/fabric-sdk-go/api/apilogging"
Expand Down Expand Up @@ -181,6 +184,9 @@ func initSDK(sdk *FabricSDK, opts []Option) error {

sdk.cryptoSuite = cs

// Initialize rand (TODO: should probably be optional)
rand.Seed(time.Now().UnixNano())

// Setting this cryptosuite as the factory default
cryptosuite.SetDefault(cs)

Expand Down
2 changes: 0 additions & 2 deletions test/integration/fab/fabric_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"path"
"strconv"
"testing"
"time"

"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
ca "github.com/hyperledger/fabric-sdk-go/api/apifabca"
Expand Down Expand Up @@ -239,6 +238,5 @@ func TestEnrollAndTransact(t *testing.T) {
}

func createRandomName() string {
rand.Seed(time.Now().UnixNano())
return "user" + strconv.Itoa(rand.Intn(500000))
}
2 changes: 0 additions & 2 deletions test/integration/fab/install_chaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strconv"
"strings"
"testing"
"time"

packager "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/ccpackager/gopackager"
"github.com/hyperledger/fabric-sdk-go/test/integration"
Expand Down Expand Up @@ -111,6 +110,5 @@ func testChaincodeInstallUsingChaincodePackage(t *testing.T, testSetup *integrat
}

func getRandomCCVersion() string {
rand.Seed(time.Now().UnixNano())
return "v0" + strconv.Itoa(rand.Intn(10000000))
}
1 change: 0 additions & 1 deletion test/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

// GenerateRandomID generates random ID
func GenerateRandomID() string {
rand.Seed(time.Now().UnixNano())
return randomString(10)
}

Expand Down

0 comments on commit 20ce0d3

Please sign in to comment.