Skip to content

Commit

Permalink
handle unlikely rounding up after sqrt
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsmooth committed Apr 5, 2015
1 parent f2e8348 commit 83ddc94
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cryptonote_core/blockchain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,9 @@ bool blockchain_storage::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDO
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);
Expand Down

0 comments on commit 83ddc94

Please sign in to comment.