This commit is contained in:
Christopher Jeffrey 2016-05-12 17:23:20 -07:00
parent 72c2d25efc
commit 679d4194b1
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 12 additions and 1 deletions

View File

@ -95,6 +95,17 @@ ec.random = function random(size) {
return new Buffer(ec.elliptic.rand(size));
};
/**
* Generate a random number within a range.
* @param {Number} min - Inclusive.
* @param {Number} max - Exclusive.
* @returns {Number}
*/
ec.rand = function rand(min, max) {
return (ec.random(1)[0] / 256) * (max - min) + min;
};
/**
* Verify a signature.
* @param {Buffer} msg

View File

@ -457,7 +457,7 @@ Mempool.prototype.limitOrphans = function limitOrphans(callback) {
if (self.totalOrphans <= constants.mempool.MAX_ORPHAN_TX)
return callback();
i = Math.random() * orphans.length | 0;
i = bcoin.ec.rand(0, orphans.length);
hash = orphans[i];
orphans.splice(i, 1);