mirror of
https://github.com/monero-project/monero.git
synced 2025-07-23 04:40:40 -04:00
blockchain: always select random outs using triangular distribution
It was only used by the older blockchain_storage. We also move the code to the calling blockchain level, to avoid replicating the code in every DB implementation. This also makes the get_random_out method obsolete, and we delete it.
This commit is contained in:
parent
9c3715e46a
commit
275894cdef
6 changed files with 9 additions and 35 deletions
|
@ -1511,7 +1511,15 @@ bool Blockchain::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUT
|
|||
// get a random output index from the DB. If we've already seen it,
|
||||
// return to the top of the loop and try again, otherwise add it to the
|
||||
// list of output indices we've seen.
|
||||
uint64_t i = m_db->get_random_output(amount);
|
||||
|
||||
// triangular distribution over [a,b) with a=0, mode c=b=up_index_limit
|
||||
uint64_t r = crypto::rand<uint64_t>() % ((uint64_t)1 << 53);
|
||||
double frac = std::sqrt((double)r / ((uint64_t)1 << 53));
|
||||
uint64_t i = (uint64_t)(frac*num_outs);
|
||||
// just in case rounding up to 1 occurs after sqrt
|
||||
if (i == num_outs)
|
||||
--i;
|
||||
|
||||
if (seen_indices.count(i))
|
||||
{
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue