mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +08:00
Merge pull request #1099 from ipfs/fix-randperm
core: bugfix: bootstrap random permutation
This commit is contained in:
@ -225,8 +225,11 @@ func toPeerInfo(bp config.BootstrapPeer) peer.PeerInfo {
|
|||||||
func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo {
|
func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo {
|
||||||
n := math2.IntMin(max, len(in))
|
n := math2.IntMin(max, len(in))
|
||||||
var out []peer.PeerInfo
|
var out []peer.PeerInfo
|
||||||
for _, val := range rand.Perm(n) {
|
for _, val := range rand.Perm(len(in)) {
|
||||||
out = append(out, in[val])
|
out = append(out, in[val])
|
||||||
|
if len(out) >= n {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user