p2p: fix cubic selection in filtered peer list

Integer quantization biased the picks a lot (leading some indices
to never be selected)
This commit is contained in:
moneromooo 2021-01-01 15:27:15 +00:00 committed by moneromooo-monero
parent a1eca8ca7e
commit 1d1c430b1f
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3

View file

@ -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;
}