aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJavier Smooth <iamjaviersmooth@gmail.com>2015-04-05 04:01:00 -0700
committerJavier Smooth <iamjaviersmooth@gmail.com>2015-04-05 04:01:00 -0700
commitf2e8348be0c91c903e68ef582cee687c52411722 (patch)
treecb77c7fa24e09aec11d6fbeab47d51cc8baa8365 /src
parentminor CMakeLists fix for Unbound, ldns -> sldns (diff)
downloadmonero-f2e8348be0c91c903e68ef582cee687c52411722.tar.xz
triangular distribution to choose recent outputs more often for mixins
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index 136d4f1d1..a5e19b061 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,10 @@ 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);
if(used.count(i))
continue;
bool added = add_out_to_get_random_outs(amount_outs, result_outs, amount, i);