aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-08-09 18:07:44 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-08-09 18:07:44 +0100
commit275894cdefeb80095b4b3463ec732c6e728f91b9 (patch)
tree7667f4d4d05e795ca1696a541c8d6fd252c69112 /src/cryptonote_core
parentMerge pull request #358 (diff)
downloadmonero-275894cdefeb80095b4b3463ec732c6e728f91b9.tar.xz
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.
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index cc2d6f821..8a81268ab 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -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;