UNPKG

989 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.generatePseudoRandom256BitNumber = void 0;
4const configured_bignumber_1 = require("./configured_bignumber");
5const MAX_DIGITS_IN_UNSIGNED_256_INT = 78;
6/**
7 * Generates a pseudo-random 256-bit number.
8 * @return A pseudo-random 256-bit number.
9 */
10function generatePseudoRandom256BitNumber() {
11 // BigNumber.random returns a pseudo-random number between 0 & 1 with a passed in number of decimal places.
12 // Source: https://mikemcl.github.io/bignumber.js/#random
13 const randomNumber = configured_bignumber_1.BigNumber.random(MAX_DIGITS_IN_UNSIGNED_256_INT);
14 const factor = new configured_bignumber_1.BigNumber(10).pow(MAX_DIGITS_IN_UNSIGNED_256_INT - 1);
15 const randomNumberScaledTo256Bits = randomNumber.times(factor).integerValue();
16 return randomNumberScaledTo256Bits;
17}
18exports.generatePseudoRandom256BitNumber = generatePseudoRandom256BitNumber;
19//# sourceMappingURL=random.js.map
\No newline at end of file