aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-04-05 17:06:03 +0200
committerRiccardo Spagni <ric@spagni.net>2015-04-05 17:07:21 +0200
commit4fb09968f7e29544593b44725cfe8f112bf13b5f (patch)
treebf0d8a2e222a0be9fc0184ac1ff97d817e8ee28b
parentminor CMakeLists fix for Unbound, ldns -> sldns (diff)
parenthandle unlikely rounding up after sqrt (diff)
downloadmonero-4fb09968f7e29544593b44725cfe8f112bf13b5f.tar.xz
Merge pull request #255
83ddc94 handle unlikely rounding up after sqrt (Javier Smooth) f2e8348 triangular distribution to choose recent outputs more often for mixins (Javier Smooth)
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index 136d4f1d1..d59fc7a58 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -30,6 +30,7 @@
#include <algorithm>
#include <cstdio>
+#include <cmath>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -1081,7 +1082,13 @@ bool blockchain_storage::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDO
size_t try_count = 0;
for(uint64_t j = 0; j != req.outs_count && try_count < up_index_limit;)
{
- size_t i = crypto::rand<size_t>()%up_index_limit;
+ // 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));
+ size_t i = (size_t)(frac*up_index_limit);
+ // just in case rounding up to 1 occurs after sqrt
+ if (i == up_index_limit)
+ --i;
if(used.count(i))
continue;
bool added = add_out_to_get_random_outs(amount_outs, result_outs, amount, i);