From ce7914063f97354f647c947a1ba966b944e4a2aa Mon Sep 17 00:00:00 2001
From: Juan Batiz-Benet <juan@benet.ai>
Date: Mon, 20 Apr 2015 06:00:42 -0700
Subject: [PATCH] core: bugfix: bootstrap random permutation

the random permutaton for bootstrap peers was not working as
intended, returning the first four bootstrap peers always.
this commit fixes it to be a random subset.
---
 core/bootstrap.go | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/core/bootstrap.go b/core/bootstrap.go
index 2fa32da18..2c4752970 100644
--- a/core/bootstrap.go
+++ b/core/bootstrap.go
@@ -225,8 +225,11 @@ func toPeerInfo(bp config.BootstrapPeer) peer.PeerInfo {
 func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo {
 	n := math2.IntMin(max, len(in))
 	var out []peer.PeerInfo
-	for _, val := range rand.Perm(n) {
+	for _, val := range rand.Perm(len(in)) {
 		out = append(out, in[val])
+		if len(out) >= n {
+			break
+		}
 	}
 	return out
 }
-- 
GitLab