random.
This commit is contained in:
parent
72c2d25efc
commit
679d4194b1
@ -95,6 +95,17 @@ ec.random = function random(size) {
|
|||||||
return new Buffer(ec.elliptic.rand(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.
|
* Verify a signature.
|
||||||
* @param {Buffer} msg
|
* @param {Buffer} msg
|
||||||
|
|||||||
@ -457,7 +457,7 @@ Mempool.prototype.limitOrphans = function limitOrphans(callback) {
|
|||||||
if (self.totalOrphans <= constants.mempool.MAX_ORPHAN_TX)
|
if (self.totalOrphans <= constants.mempool.MAX_ORPHAN_TX)
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
i = Math.random() * orphans.length | 0;
|
i = bcoin.ec.rand(0, orphans.length);
|
||||||
hash = orphans[i];
|
hash = orphans[i];
|
||||||
orphans.splice(i, 1);
|
orphans.splice(i, 1);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user