This commit is contained in:
parent
7a9bf3199a
commit
c294e2e9ae
5702 changed files with 465039 additions and 34 deletions
36
node_modules/pure-rand/lib/distribution/UnsafeUniformBigIntDistribution.js
generated
vendored
Normal file
36
node_modules/pure-rand/lib/distribution/UnsafeUniformBigIntDistribution.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unsafeUniformBigIntDistribution = unsafeUniformBigIntDistribution;
|
||||
var SBigInt = typeof BigInt !== 'undefined' ? BigInt : undefined;
|
||||
var One = typeof BigInt !== 'undefined' ? BigInt(1) : undefined;
|
||||
var ThirtyTwo = typeof BigInt !== 'undefined' ? BigInt(32) : undefined;
|
||||
var NumValues = typeof BigInt !== 'undefined' ? BigInt(0x100000000) : undefined;
|
||||
function unsafeUniformBigIntDistribution(from, to, rng) {
|
||||
var diff = to - from + One;
|
||||
var FinalNumValues = NumValues;
|
||||
var NumIterations = 1;
|
||||
while (FinalNumValues < diff) {
|
||||
FinalNumValues <<= ThirtyTwo;
|
||||
++NumIterations;
|
||||
}
|
||||
var value = generateNext(NumIterations, rng);
|
||||
if (value < diff) {
|
||||
return value + from;
|
||||
}
|
||||
if (value + diff < FinalNumValues) {
|
||||
return (value % diff) + from;
|
||||
}
|
||||
var MaxAcceptedRandom = FinalNumValues - (FinalNumValues % diff);
|
||||
while (value >= MaxAcceptedRandom) {
|
||||
value = generateNext(NumIterations, rng);
|
||||
}
|
||||
return (value % diff) + from;
|
||||
}
|
||||
function generateNext(NumIterations, rng) {
|
||||
var value = SBigInt(rng.unsafeNext() + 0x80000000);
|
||||
for (var num = 1; num < NumIterations; ++num) {
|
||||
var out = rng.unsafeNext();
|
||||
value = (value << ThirtyTwo) + SBigInt(out + 0x80000000);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue