p2p: fix cubic selection in filtered peer list

Integer quantization biased the picks a lot (leading some indices
to never be selected)
release-v0.10.0.3
moneromooo 4 years ago committed by moneromooo-monero
parent a1eca8ca7e
commit 1d1c430b1f
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3

@ -1243,8 +1243,8 @@ namespace nodetool
if(!max_index)
return 0;
size_t x = crypto::rand<size_t>()%(max_index+1);
size_t res = (x*x*x)/(max_index*max_index); //parabola \/
size_t x = crypto::rand<size_t>()%(16*max_index+1);
size_t res = (x*x*x)/(max_index*max_index*16*16*16); //parabola \/
MDEBUG("Random connection index=" << res << "(x="<< x << ", max_index=" << max_index << ")");
return res;
}

Loading…
Cancel
Save