diff --git a/pkg/fabric-client/txn/txn.go b/pkg/fabric-client/txn/txn.go index a19cf83653..4dd8228c37 100644 --- a/pkg/fabric-client/txn/txn.go +++ b/pkg/fabric-client/txn/txn.go @@ -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 diff --git a/pkg/fabric-txn/selection/dynamicselection/pgresolver/lbpolicyimpl.go b/pkg/fabric-txn/selection/dynamicselection/pgresolver/lbpolicyimpl.go index a80e57364c..e958510aac 100644 --- a/pkg/fabric-txn/selection/dynamicselection/pgresolver/lbpolicyimpl.go +++ b/pkg/fabric-txn/selection/dynamicselection/pgresolver/lbpolicyimpl.go @@ -8,7 +8,6 @@ package pgresolver import ( "math/rand" - "time" ) type randomLBP struct { @@ -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) @@ -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++ diff --git a/pkg/fabsdk/fabsdk.go b/pkg/fabsdk/fabsdk.go index 8537b7cd4a..77c30821d9 100644 --- a/pkg/fabsdk/fabsdk.go +++ b/pkg/fabsdk/fabsdk.go @@ -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" @@ -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) diff --git a/test/integration/fab/fabric_ca_test.go b/test/integration/fab/fabric_ca_test.go index a99e0bce01..2e16fb2762 100644 --- a/test/integration/fab/fabric_ca_test.go +++ b/test/integration/fab/fabric_ca_test.go @@ -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" @@ -239,6 +238,5 @@ func TestEnrollAndTransact(t *testing.T) { } func createRandomName() string { - rand.Seed(time.Now().UnixNano()) return "user" + strconv.Itoa(rand.Intn(500000)) } diff --git a/test/integration/fab/install_chaincode_test.go b/test/integration/fab/install_chaincode_test.go index 76992e13ab..c26d4225e4 100644 --- a/test/integration/fab/install_chaincode_test.go +++ b/test/integration/fab/install_chaincode_test.go @@ -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" @@ -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)) } diff --git a/test/integration/utils.go b/test/integration/utils.go index ddbde892fc..e877987427 100644 --- a/test/integration/utils.go +++ b/test/integration/utils.go @@ -20,7 +20,6 @@ import ( // GenerateRandomID generates random ID func GenerateRandomID() string { - rand.Seed(time.Now().UnixNano()) return randomString(10) }