Change endpoint from persons to people

This commit is contained in:
xfarrow
2025-03-23 21:00:08 +01:00
parent 4ae263662c
commit d005193f63
7158 changed files with 700476 additions and 735 deletions

View File

@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

View File

@ -0,0 +1,15 @@
"use strict";
exports.__esModule = true;
exports.uniformArrayIntDistribution = void 0;
var UnsafeUniformArrayIntDistribution_1 = require("./UnsafeUniformArrayIntDistribution");
function uniformArrayIntDistribution(from, to, rng) {
if (rng != null) {
var nextRng = rng.clone();
return [(0, UnsafeUniformArrayIntDistribution_1.unsafeUniformArrayIntDistribution)(from, to, nextRng), nextRng];
}
return function (rng) {
var nextRng = rng.clone();
return [(0, UnsafeUniformArrayIntDistribution_1.unsafeUniformArrayIntDistribution)(from, to, nextRng), nextRng];
};
}
exports.uniformArrayIntDistribution = uniformArrayIntDistribution;

View File

@ -0,0 +1,15 @@
"use strict";
exports.__esModule = true;
exports.uniformBigIntDistribution = void 0;
var UnsafeUniformBigIntDistribution_1 = require("./UnsafeUniformBigIntDistribution");
function uniformBigIntDistribution(from, to, rng) {
if (rng != null) {
var nextRng = rng.clone();
return [(0, UnsafeUniformBigIntDistribution_1.unsafeUniformBigIntDistribution)(from, to, nextRng), nextRng];
}
return function (rng) {
var nextRng = rng.clone();
return [(0, UnsafeUniformBigIntDistribution_1.unsafeUniformBigIntDistribution)(from, to, nextRng), nextRng];
};
}
exports.uniformBigIntDistribution = uniformBigIntDistribution;

View File

@ -0,0 +1,15 @@
"use strict";
exports.__esModule = true;
exports.uniformIntDistribution = void 0;
var UnsafeUniformIntDistribution_1 = require("./UnsafeUniformIntDistribution");
function uniformIntDistribution(from, to, rng) {
if (rng != null) {
var nextRng = rng.clone();
return [(0, UnsafeUniformIntDistribution_1.unsafeUniformIntDistribution)(from, to, nextRng), nextRng];
}
return function (rng) {
var nextRng = rng.clone();
return [(0, UnsafeUniformIntDistribution_1.unsafeUniformIntDistribution)(from, to, nextRng), nextRng];
};
}
exports.uniformIntDistribution = uniformIntDistribution;

View File

@ -0,0 +1,12 @@
"use strict";
exports.__esModule = true;
exports.unsafeUniformArrayIntDistribution = void 0;
var ArrayInt_1 = require("./internals/ArrayInt");
var UnsafeUniformArrayIntDistributionInternal_1 = require("./internals/UnsafeUniformArrayIntDistributionInternal");
function unsafeUniformArrayIntDistribution(from, to, rng) {
var rangeSize = (0, ArrayInt_1.trimArrayIntInplace)((0, ArrayInt_1.addOneToPositiveArrayInt)((0, ArrayInt_1.substractArrayIntToNew)(to, from)));
var emptyArrayIntData = rangeSize.data.slice(0);
var g = (0, UnsafeUniformArrayIntDistributionInternal_1.unsafeUniformArrayIntDistributionInternal)(emptyArrayIntData, rangeSize.data, rng);
return (0, ArrayInt_1.trimArrayIntInplace)((0, ArrayInt_1.addArrayIntToNew)({ sign: 1, data: g }, from));
}
exports.unsafeUniformArrayIntDistribution = unsafeUniformArrayIntDistribution;

View File

@ -0,0 +1,28 @@
"use strict";
exports.__esModule = true;
exports.unsafeUniformBigIntDistribution = void 0;
var SBigInt = typeof BigInt !== 'undefined' ? BigInt : undefined;
function unsafeUniformBigIntDistribution(from, to, rng) {
var diff = to - from + SBigInt(1);
var MinRng = SBigInt(-0x80000000);
var NumValues = SBigInt(0x100000000);
var FinalNumValues = NumValues;
var NumIterations = 1;
while (FinalNumValues < diff) {
FinalNumValues *= NumValues;
++NumIterations;
}
var MaxAcceptedRandom = FinalNumValues - (FinalNumValues % diff);
while (true) {
var value = SBigInt(0);
for (var num = 0; num !== NumIterations; ++num) {
var out = rng.unsafeNext();
value = NumValues * value + (SBigInt(out) - MinRng);
}
if (value < MaxAcceptedRandom) {
var inDiff = value % diff;
return inDiff + from;
}
}
}
exports.unsafeUniformBigIntDistribution = unsafeUniformBigIntDistribution;

View File

@ -0,0 +1,34 @@
"use strict";
exports.__esModule = true;
exports.unsafeUniformIntDistribution = void 0;
var UnsafeUniformIntDistributionInternal_1 = require("./internals/UnsafeUniformIntDistributionInternal");
var ArrayInt_1 = require("./internals/ArrayInt");
var UnsafeUniformArrayIntDistributionInternal_1 = require("./internals/UnsafeUniformArrayIntDistributionInternal");
var safeNumberMaxSafeInteger = Number.MAX_SAFE_INTEGER;
var sharedA = { sign: 1, data: [0, 0] };
var sharedB = { sign: 1, data: [0, 0] };
var sharedC = { sign: 1, data: [0, 0] };
var sharedData = [0, 0];
function uniformLargeIntInternal(from, to, rangeSize, rng) {
var rangeSizeArrayIntValue = rangeSize <= safeNumberMaxSafeInteger
? (0, ArrayInt_1.fromNumberToArrayInt64)(sharedC, rangeSize)
: (0, ArrayInt_1.substractArrayInt64)(sharedC, (0, ArrayInt_1.fromNumberToArrayInt64)(sharedA, to), (0, ArrayInt_1.fromNumberToArrayInt64)(sharedB, from));
if (rangeSizeArrayIntValue.data[1] === 0xffffffff) {
rangeSizeArrayIntValue.data[0] += 1;
rangeSizeArrayIntValue.data[1] = 0;
}
else {
rangeSizeArrayIntValue.data[1] += 1;
}
(0, UnsafeUniformArrayIntDistributionInternal_1.unsafeUniformArrayIntDistributionInternal)(sharedData, rangeSizeArrayIntValue.data, rng);
return sharedData[0] * 0x100000000 + sharedData[1] + from;
}
function unsafeUniformIntDistribution(from, to, rng) {
var rangeSize = to - from;
if (rangeSize <= 0xffffffff) {
var g = (0, UnsafeUniformIntDistributionInternal_1.unsafeUniformIntDistributionInternal)(rangeSize + 1, rng);
return g + from;
}
return uniformLargeIntInternal(from, to, rangeSize, rng);
}
exports.unsafeUniformIntDistribution = unsafeUniformIntDistribution;

View File

@ -0,0 +1,141 @@
"use strict";
exports.__esModule = true;
exports.substractArrayInt64 = exports.fromNumberToArrayInt64 = exports.trimArrayIntInplace = exports.substractArrayIntToNew = exports.addOneToPositiveArrayInt = exports.addArrayIntToNew = void 0;
function addArrayIntToNew(arrayIntA, arrayIntB) {
if (arrayIntA.sign !== arrayIntB.sign) {
return substractArrayIntToNew(arrayIntA, { sign: -arrayIntB.sign, data: arrayIntB.data });
}
var data = [];
var reminder = 0;
var dataA = arrayIntA.data;
var dataB = arrayIntB.data;
for (var indexA = dataA.length - 1, indexB = dataB.length - 1; indexA >= 0 || indexB >= 0; --indexA, --indexB) {
var vA = indexA >= 0 ? dataA[indexA] : 0;
var vB = indexB >= 0 ? dataB[indexB] : 0;
var current = vA + vB + reminder;
data.push(current >>> 0);
reminder = ~~(current / 0x100000000);
}
if (reminder !== 0) {
data.push(reminder);
}
return { sign: arrayIntA.sign, data: data.reverse() };
}
exports.addArrayIntToNew = addArrayIntToNew;
function addOneToPositiveArrayInt(arrayInt) {
arrayInt.sign = 1;
var data = arrayInt.data;
for (var index = data.length - 1; index >= 0; --index) {
if (data[index] === 0xffffffff) {
data[index] = 0;
}
else {
data[index] += 1;
return arrayInt;
}
}
data.unshift(1);
return arrayInt;
}
exports.addOneToPositiveArrayInt = addOneToPositiveArrayInt;
function isStrictlySmaller(dataA, dataB) {
var maxLength = Math.max(dataA.length, dataB.length);
for (var index = 0; index < maxLength; ++index) {
var indexA = index + dataA.length - maxLength;
var indexB = index + dataB.length - maxLength;
var vA = indexA >= 0 ? dataA[indexA] : 0;
var vB = indexB >= 0 ? dataB[indexB] : 0;
if (vA < vB)
return true;
if (vA > vB)
return false;
}
return false;
}
function substractArrayIntToNew(arrayIntA, arrayIntB) {
if (arrayIntA.sign !== arrayIntB.sign) {
return addArrayIntToNew(arrayIntA, { sign: -arrayIntB.sign, data: arrayIntB.data });
}
var dataA = arrayIntA.data;
var dataB = arrayIntB.data;
if (isStrictlySmaller(dataA, dataB)) {
var out = substractArrayIntToNew(arrayIntB, arrayIntA);
out.sign = -out.sign;
return out;
}
var data = [];
var reminder = 0;
for (var indexA = dataA.length - 1, indexB = dataB.length - 1; indexA >= 0 || indexB >= 0; --indexA, --indexB) {
var vA = indexA >= 0 ? dataA[indexA] : 0;
var vB = indexB >= 0 ? dataB[indexB] : 0;
var current = vA - vB - reminder;
data.push(current >>> 0);
reminder = current < 0 ? 1 : 0;
}
return { sign: arrayIntA.sign, data: data.reverse() };
}
exports.substractArrayIntToNew = substractArrayIntToNew;
function trimArrayIntInplace(arrayInt) {
var data = arrayInt.data;
var firstNonZero = 0;
for (; firstNonZero !== data.length && data[firstNonZero] === 0; ++firstNonZero) { }
if (firstNonZero === data.length) {
arrayInt.sign = 1;
arrayInt.data = [0];
return arrayInt;
}
data.splice(0, firstNonZero);
return arrayInt;
}
exports.trimArrayIntInplace = trimArrayIntInplace;
function fromNumberToArrayInt64(out, n) {
if (n < 0) {
var posN = -n;
out.sign = -1;
out.data[0] = ~~(posN / 0x100000000);
out.data[1] = posN >>> 0;
}
else {
out.sign = 1;
out.data[0] = ~~(n / 0x100000000);
out.data[1] = n >>> 0;
}
return out;
}
exports.fromNumberToArrayInt64 = fromNumberToArrayInt64;
function substractArrayInt64(out, arrayIntA, arrayIntB) {
var lowA = arrayIntA.data[1];
var highA = arrayIntA.data[0];
var signA = arrayIntA.sign;
var lowB = arrayIntB.data[1];
var highB = arrayIntB.data[0];
var signB = arrayIntB.sign;
out.sign = 1;
if (signA === 1 && signB === -1) {
var low_1 = lowA + lowB;
var high = highA + highB + (low_1 > 0xffffffff ? 1 : 0);
out.data[0] = high >>> 0;
out.data[1] = low_1 >>> 0;
return out;
}
var lowFirst = lowA;
var highFirst = highA;
var lowSecond = lowB;
var highSecond = highB;
if (signA === -1) {
lowFirst = lowB;
highFirst = highB;
lowSecond = lowA;
highSecond = highA;
}
var reminderLow = 0;
var low = lowFirst - lowSecond;
if (low < 0) {
reminderLow = 1;
low = low >>> 0;
}
out.data[0] = highFirst - highSecond - reminderLow;
out.data[1] = low;
return out;
}
exports.substractArrayInt64 = substractArrayInt64;

View File

@ -0,0 +1,25 @@
"use strict";
exports.__esModule = true;
exports.unsafeUniformArrayIntDistributionInternal = void 0;
var UnsafeUniformIntDistributionInternal_1 = require("./UnsafeUniformIntDistributionInternal");
function unsafeUniformArrayIntDistributionInternal(out, rangeSize, rng) {
var rangeLength = rangeSize.length;
while (true) {
for (var index = 0; index !== rangeLength; ++index) {
var indexRangeSize = index === 0 ? rangeSize[0] + 1 : 0x100000000;
var g = (0, UnsafeUniformIntDistributionInternal_1.unsafeUniformIntDistributionInternal)(indexRangeSize, rng);
out[index] = g;
}
for (var index = 0; index !== rangeLength; ++index) {
var current = out[index];
var currentInRange = rangeSize[index];
if (current < currentInRange) {
return out;
}
else if (current > currentInRange) {
break;
}
}
}
}
exports.unsafeUniformArrayIntDistributionInternal = unsafeUniformArrayIntDistributionInternal;

View File

@ -0,0 +1,12 @@
"use strict";
exports.__esModule = true;
exports.unsafeUniformIntDistributionInternal = void 0;
function unsafeUniformIntDistributionInternal(rangeSize, rng) {
var MaxAllowed = rangeSize > 2 ? ~~(0x100000000 / rangeSize) * rangeSize : 0x100000000;
var deltaV = rng.unsafeNext() + 0x80000000;
while (deltaV >= MaxAllowed) {
deltaV = rng.unsafeNext() + 0x80000000;
}
return deltaV % rangeSize;
}
exports.unsafeUniformIntDistributionInternal = unsafeUniformIntDistributionInternal;

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,12 @@
import { unsafeUniformArrayIntDistribution } from './UnsafeUniformArrayIntDistribution.js';
function uniformArrayIntDistribution(from, to, rng) {
if (rng != null) {
var nextRng = rng.clone();
return [unsafeUniformArrayIntDistribution(from, to, nextRng), nextRng];
}
return function (rng) {
var nextRng = rng.clone();
return [unsafeUniformArrayIntDistribution(from, to, nextRng), nextRng];
};
}
export { uniformArrayIntDistribution };

View File

@ -0,0 +1,12 @@
import { unsafeUniformBigIntDistribution } from './UnsafeUniformBigIntDistribution.js';
function uniformBigIntDistribution(from, to, rng) {
if (rng != null) {
var nextRng = rng.clone();
return [unsafeUniformBigIntDistribution(from, to, nextRng), nextRng];
}
return function (rng) {
var nextRng = rng.clone();
return [unsafeUniformBigIntDistribution(from, to, nextRng), nextRng];
};
}
export { uniformBigIntDistribution };

View File

@ -0,0 +1,12 @@
import { unsafeUniformIntDistribution } from './UnsafeUniformIntDistribution.js';
function uniformIntDistribution(from, to, rng) {
if (rng != null) {
var nextRng = rng.clone();
return [unsafeUniformIntDistribution(from, to, nextRng), nextRng];
}
return function (rng) {
var nextRng = rng.clone();
return [unsafeUniformIntDistribution(from, to, nextRng), nextRng];
};
}
export { uniformIntDistribution };

View File

@ -0,0 +1,8 @@
import { addArrayIntToNew, addOneToPositiveArrayInt, substractArrayIntToNew, trimArrayIntInplace, } from './internals/ArrayInt.js';
import { unsafeUniformArrayIntDistributionInternal } from './internals/UnsafeUniformArrayIntDistributionInternal.js';
export function unsafeUniformArrayIntDistribution(from, to, rng) {
var rangeSize = trimArrayIntInplace(addOneToPositiveArrayInt(substractArrayIntToNew(to, from)));
var emptyArrayIntData = rangeSize.data.slice(0);
var g = unsafeUniformArrayIntDistributionInternal(emptyArrayIntData, rangeSize.data, rng);
return trimArrayIntInplace(addArrayIntToNew({ sign: 1, data: g }, from));
}

View File

@ -0,0 +1,24 @@
var SBigInt = typeof BigInt !== 'undefined' ? BigInt : undefined;
export function unsafeUniformBigIntDistribution(from, to, rng) {
var diff = to - from + SBigInt(1);
var MinRng = SBigInt(-0x80000000);
var NumValues = SBigInt(0x100000000);
var FinalNumValues = NumValues;
var NumIterations = 1;
while (FinalNumValues < diff) {
FinalNumValues *= NumValues;
++NumIterations;
}
var MaxAcceptedRandom = FinalNumValues - (FinalNumValues % diff);
while (true) {
var value = SBigInt(0);
for (var num = 0; num !== NumIterations; ++num) {
var out = rng.unsafeNext();
value = NumValues * value + (SBigInt(out) - MinRng);
}
if (value < MaxAcceptedRandom) {
var inDiff = value % diff;
return inDiff + from;
}
}
}

View File

@ -0,0 +1,30 @@
import { unsafeUniformIntDistributionInternal } from './internals/UnsafeUniformIntDistributionInternal.js';
import { fromNumberToArrayInt64, substractArrayInt64 } from './internals/ArrayInt.js';
import { unsafeUniformArrayIntDistributionInternal } from './internals/UnsafeUniformArrayIntDistributionInternal.js';
var safeNumberMaxSafeInteger = Number.MAX_SAFE_INTEGER;
var sharedA = { sign: 1, data: [0, 0] };
var sharedB = { sign: 1, data: [0, 0] };
var sharedC = { sign: 1, data: [0, 0] };
var sharedData = [0, 0];
function uniformLargeIntInternal(from, to, rangeSize, rng) {
var rangeSizeArrayIntValue = rangeSize <= safeNumberMaxSafeInteger
? fromNumberToArrayInt64(sharedC, rangeSize)
: substractArrayInt64(sharedC, fromNumberToArrayInt64(sharedA, to), fromNumberToArrayInt64(sharedB, from));
if (rangeSizeArrayIntValue.data[1] === 0xffffffff) {
rangeSizeArrayIntValue.data[0] += 1;
rangeSizeArrayIntValue.data[1] = 0;
}
else {
rangeSizeArrayIntValue.data[1] += 1;
}
unsafeUniformArrayIntDistributionInternal(sharedData, rangeSizeArrayIntValue.data, rng);
return sharedData[0] * 0x100000000 + sharedData[1] + from;
}
export function unsafeUniformIntDistribution(from, to, rng) {
var rangeSize = to - from;
if (rangeSize <= 0xffffffff) {
var g = unsafeUniformIntDistributionInternal(rangeSize + 1, rng);
return g + from;
}
return uniformLargeIntInternal(from, to, rangeSize, rng);
}

View File

@ -0,0 +1,132 @@
export function addArrayIntToNew(arrayIntA, arrayIntB) {
if (arrayIntA.sign !== arrayIntB.sign) {
return substractArrayIntToNew(arrayIntA, { sign: -arrayIntB.sign, data: arrayIntB.data });
}
var data = [];
var reminder = 0;
var dataA = arrayIntA.data;
var dataB = arrayIntB.data;
for (var indexA = dataA.length - 1, indexB = dataB.length - 1; indexA >= 0 || indexB >= 0; --indexA, --indexB) {
var vA = indexA >= 0 ? dataA[indexA] : 0;
var vB = indexB >= 0 ? dataB[indexB] : 0;
var current = vA + vB + reminder;
data.push(current >>> 0);
reminder = ~~(current / 0x100000000);
}
if (reminder !== 0) {
data.push(reminder);
}
return { sign: arrayIntA.sign, data: data.reverse() };
}
export function addOneToPositiveArrayInt(arrayInt) {
arrayInt.sign = 1;
var data = arrayInt.data;
for (var index = data.length - 1; index >= 0; --index) {
if (data[index] === 0xffffffff) {
data[index] = 0;
}
else {
data[index] += 1;
return arrayInt;
}
}
data.unshift(1);
return arrayInt;
}
function isStrictlySmaller(dataA, dataB) {
var maxLength = Math.max(dataA.length, dataB.length);
for (var index = 0; index < maxLength; ++index) {
var indexA = index + dataA.length - maxLength;
var indexB = index + dataB.length - maxLength;
var vA = indexA >= 0 ? dataA[indexA] : 0;
var vB = indexB >= 0 ? dataB[indexB] : 0;
if (vA < vB)
return true;
if (vA > vB)
return false;
}
return false;
}
export function substractArrayIntToNew(arrayIntA, arrayIntB) {
if (arrayIntA.sign !== arrayIntB.sign) {
return addArrayIntToNew(arrayIntA, { sign: -arrayIntB.sign, data: arrayIntB.data });
}
var dataA = arrayIntA.data;
var dataB = arrayIntB.data;
if (isStrictlySmaller(dataA, dataB)) {
var out = substractArrayIntToNew(arrayIntB, arrayIntA);
out.sign = -out.sign;
return out;
}
var data = [];
var reminder = 0;
for (var indexA = dataA.length - 1, indexB = dataB.length - 1; indexA >= 0 || indexB >= 0; --indexA, --indexB) {
var vA = indexA >= 0 ? dataA[indexA] : 0;
var vB = indexB >= 0 ? dataB[indexB] : 0;
var current = vA - vB - reminder;
data.push(current >>> 0);
reminder = current < 0 ? 1 : 0;
}
return { sign: arrayIntA.sign, data: data.reverse() };
}
export function trimArrayIntInplace(arrayInt) {
var data = arrayInt.data;
var firstNonZero = 0;
for (; firstNonZero !== data.length && data[firstNonZero] === 0; ++firstNonZero) { }
if (firstNonZero === data.length) {
arrayInt.sign = 1;
arrayInt.data = [0];
return arrayInt;
}
data.splice(0, firstNonZero);
return arrayInt;
}
export function fromNumberToArrayInt64(out, n) {
if (n < 0) {
var posN = -n;
out.sign = -1;
out.data[0] = ~~(posN / 0x100000000);
out.data[1] = posN >>> 0;
}
else {
out.sign = 1;
out.data[0] = ~~(n / 0x100000000);
out.data[1] = n >>> 0;
}
return out;
}
export function substractArrayInt64(out, arrayIntA, arrayIntB) {
var lowA = arrayIntA.data[1];
var highA = arrayIntA.data[0];
var signA = arrayIntA.sign;
var lowB = arrayIntB.data[1];
var highB = arrayIntB.data[0];
var signB = arrayIntB.sign;
out.sign = 1;
if (signA === 1 && signB === -1) {
var low_1 = lowA + lowB;
var high = highA + highB + (low_1 > 0xffffffff ? 1 : 0);
out.data[0] = high >>> 0;
out.data[1] = low_1 >>> 0;
return out;
}
var lowFirst = lowA;
var highFirst = highA;
var lowSecond = lowB;
var highSecond = highB;
if (signA === -1) {
lowFirst = lowB;
highFirst = highB;
lowSecond = lowA;
highSecond = highA;
}
var reminderLow = 0;
var low = lowFirst - lowSecond;
if (low < 0) {
reminderLow = 1;
low = low >>> 0;
}
out.data[0] = highFirst - highSecond - reminderLow;
out.data[1] = low;
return out;
}

View File

@ -0,0 +1,21 @@
import { unsafeUniformIntDistributionInternal } from './UnsafeUniformIntDistributionInternal.js';
export function unsafeUniformArrayIntDistributionInternal(out, rangeSize, rng) {
var rangeLength = rangeSize.length;
while (true) {
for (var index = 0; index !== rangeLength; ++index) {
var indexRangeSize = index === 0 ? rangeSize[0] + 1 : 0x100000000;
var g = unsafeUniformIntDistributionInternal(indexRangeSize, rng);
out[index] = g;
}
for (var index = 0; index !== rangeLength; ++index) {
var current = out[index];
var currentInRange = rangeSize[index];
if (current < currentInRange) {
return out;
}
else if (current > currentInRange) {
break;
}
}
}
}

View File

@ -0,0 +1,8 @@
export function unsafeUniformIntDistributionInternal(rangeSize, rng) {
var MaxAllowed = rangeSize > 2 ? ~~(0x100000000 / rangeSize) * rangeSize : 0x100000000;
var deltaV = rng.unsafeNext() + 0x80000000;
while (deltaV >= MaxAllowed) {
deltaV = rng.unsafeNext() + 0x80000000;
}
return deltaV % rangeSize;
}

View File

@ -0,0 +1,47 @@
var MULTIPLIER = 0x000343fd;
var INCREMENT = 0x00269ec3;
var MASK = 0xffffffff;
var MASK_2 = (1 << 31) - 1;
var computeNextSeed = function (seed) {
return (seed * MULTIPLIER + INCREMENT) & MASK;
};
var computeValueFromNextSeed = function (nextseed) {
return (nextseed & MASK_2) >> 16;
};
var LinearCongruential32 = (function () {
function LinearCongruential32(seed) {
this.seed = seed;
}
LinearCongruential32.prototype.clone = function () {
return new LinearCongruential32(this.seed);
};
LinearCongruential32.prototype.next = function () {
var nextRng = new LinearCongruential32(this.seed);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
LinearCongruential32.prototype.unsafeNext = function () {
var s1 = computeNextSeed(this.seed);
var v1 = computeValueFromNextSeed(s1);
var s2 = computeNextSeed(s1);
var v2 = computeValueFromNextSeed(s2);
this.seed = computeNextSeed(s2);
var v3 = computeValueFromNextSeed(this.seed);
var vnext = v3 + ((v2 + (v1 << 15)) << 15);
return vnext | 0;
};
LinearCongruential32.prototype.getState = function () {
return [this.seed];
};
return LinearCongruential32;
}());
function fromState(state) {
var valid = state.length === 1;
if (!valid) {
throw new Error('The state must have been produced by a congruential32 RandomGenerator');
}
return new LinearCongruential32(state[0]);
}
export var congruential32 = Object.assign(function (seed) {
return new LinearCongruential32(seed);
}, { fromState: fromState });

View File

@ -0,0 +1,107 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var MersenneTwister = (function () {
function MersenneTwister(states, index) {
this.states = states;
this.index = index;
}
MersenneTwister.twist = function (prev) {
var mt = prev.slice();
for (var idx = 0; idx !== MersenneTwister.N - MersenneTwister.M; ++idx) {
var y_1 = (mt[idx] & MersenneTwister.MASK_UPPER) + (mt[idx + 1] & MersenneTwister.MASK_LOWER);
mt[idx] = mt[idx + MersenneTwister.M] ^ (y_1 >>> 1) ^ (-(y_1 & 1) & MersenneTwister.A);
}
for (var idx = MersenneTwister.N - MersenneTwister.M; idx !== MersenneTwister.N - 1; ++idx) {
var y_2 = (mt[idx] & MersenneTwister.MASK_UPPER) + (mt[idx + 1] & MersenneTwister.MASK_LOWER);
mt[idx] = mt[idx + MersenneTwister.M - MersenneTwister.N] ^ (y_2 >>> 1) ^ (-(y_2 & 1) & MersenneTwister.A);
}
var y = (mt[MersenneTwister.N - 1] & MersenneTwister.MASK_UPPER) + (mt[0] & MersenneTwister.MASK_LOWER);
mt[MersenneTwister.N - 1] = mt[MersenneTwister.M - 1] ^ (y >>> 1) ^ (-(y & 1) & MersenneTwister.A);
return mt;
};
MersenneTwister.seeded = function (seed) {
var out = Array(MersenneTwister.N);
out[0] = seed;
for (var idx = 1; idx !== MersenneTwister.N; ++idx) {
var xored = out[idx - 1] ^ (out[idx - 1] >>> 30);
out[idx] = (Math.imul(MersenneTwister.F, xored) + idx) | 0;
}
return out;
};
MersenneTwister.from = function (seed) {
return new MersenneTwister(MersenneTwister.twist(MersenneTwister.seeded(seed)), 0);
};
MersenneTwister.prototype.clone = function () {
return new MersenneTwister(this.states, this.index);
};
MersenneTwister.prototype.next = function () {
var nextRng = new MersenneTwister(this.states, this.index);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
MersenneTwister.prototype.unsafeNext = function () {
var y = this.states[this.index];
y ^= this.states[this.index] >>> MersenneTwister.U;
y ^= (y << MersenneTwister.S) & MersenneTwister.B;
y ^= (y << MersenneTwister.T) & MersenneTwister.C;
y ^= y >>> MersenneTwister.L;
if (++this.index >= MersenneTwister.N) {
this.states = MersenneTwister.twist(this.states);
this.index = 0;
}
return y;
};
MersenneTwister.prototype.getState = function () {
return __spreadArray([this.index], __read(this.states), false);
};
MersenneTwister.fromState = function (state) {
var valid = state.length === MersenneTwister.N + 1 && state[0] >= 0 && state[0] < MersenneTwister.N;
if (!valid) {
throw new Error('The state must have been produced by a mersenne RandomGenerator');
}
return new MersenneTwister(state.slice(1), state[0]);
};
MersenneTwister.N = 624;
MersenneTwister.M = 397;
MersenneTwister.R = 31;
MersenneTwister.A = 0x9908b0df;
MersenneTwister.F = 1812433253;
MersenneTwister.U = 11;
MersenneTwister.S = 7;
MersenneTwister.B = 0x9d2c5680;
MersenneTwister.T = 15;
MersenneTwister.C = 0xefc60000;
MersenneTwister.L = 18;
MersenneTwister.MASK_LOWER = Math.pow(2, MersenneTwister.R) - 1;
MersenneTwister.MASK_UPPER = Math.pow(2, MersenneTwister.R);
return MersenneTwister;
}());
function fromState(state) {
return MersenneTwister.fromState(state);
}
export default Object.assign(function (seed) {
return MersenneTwister.from(seed);
}, { fromState: fromState });

View File

@ -0,0 +1,22 @@
export function unsafeGenerateN(rng, num) {
var out = [];
for (var idx = 0; idx != num; ++idx) {
out.push(rng.unsafeNext());
}
return out;
}
export function generateN(rng, num) {
var nextRng = rng.clone();
var out = unsafeGenerateN(nextRng, num);
return [out, nextRng];
}
export function unsafeSkipN(rng, num) {
for (var idx = 0; idx != num; ++idx) {
rng.unsafeNext();
}
}
export function skipN(rng, num) {
var nextRng = rng.clone();
unsafeSkipN(nextRng, num);
return nextRng;
}

View File

@ -0,0 +1,69 @@
var XorShift128Plus = (function () {
function XorShift128Plus(s01, s00, s11, s10) {
this.s01 = s01;
this.s00 = s00;
this.s11 = s11;
this.s10 = s10;
}
XorShift128Plus.prototype.clone = function () {
return new XorShift128Plus(this.s01, this.s00, this.s11, this.s10);
};
XorShift128Plus.prototype.next = function () {
var nextRng = new XorShift128Plus(this.s01, this.s00, this.s11, this.s10);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
XorShift128Plus.prototype.unsafeNext = function () {
var a0 = this.s00 ^ (this.s00 << 23);
var a1 = this.s01 ^ ((this.s01 << 23) | (this.s00 >>> 9));
var b0 = a0 ^ this.s10 ^ ((a0 >>> 18) | (a1 << 14)) ^ ((this.s10 >>> 5) | (this.s11 << 27));
var b1 = a1 ^ this.s11 ^ (a1 >>> 18) ^ (this.s11 >>> 5);
var out = (this.s00 + this.s10) | 0;
this.s01 = this.s11;
this.s00 = this.s10;
this.s11 = b1;
this.s10 = b0;
return out;
};
XorShift128Plus.prototype.jump = function () {
var nextRng = new XorShift128Plus(this.s01, this.s00, this.s11, this.s10);
nextRng.unsafeJump();
return nextRng;
};
XorShift128Plus.prototype.unsafeJump = function () {
var ns01 = 0;
var ns00 = 0;
var ns11 = 0;
var ns10 = 0;
var jump = [0x635d2dff, 0x8a5cd789, 0x5c472f96, 0x121fd215];
for (var i = 0; i !== 4; ++i) {
for (var mask = 1; mask; mask <<= 1) {
if (jump[i] & mask) {
ns01 ^= this.s01;
ns00 ^= this.s00;
ns11 ^= this.s11;
ns10 ^= this.s10;
}
this.unsafeNext();
}
}
this.s01 = ns01;
this.s00 = ns00;
this.s11 = ns11;
this.s10 = ns10;
};
XorShift128Plus.prototype.getState = function () {
return [this.s01, this.s00, this.s11, this.s10];
};
return XorShift128Plus;
}());
function fromState(state) {
var valid = state.length === 4;
if (!valid) {
throw new Error('The state must have been produced by a xorshift128plus RandomGenerator');
}
return new XorShift128Plus(state[0], state[1], state[2], state[3]);
}
export var xorshift128plus = Object.assign(function (seed) {
return new XorShift128Plus(-1, ~seed, seed | 0, 0);
}, { fromState: fromState });

View File

@ -0,0 +1,69 @@
var XoroShiro128Plus = (function () {
function XoroShiro128Plus(s01, s00, s11, s10) {
this.s01 = s01;
this.s00 = s00;
this.s11 = s11;
this.s10 = s10;
}
XoroShiro128Plus.prototype.clone = function () {
return new XoroShiro128Plus(this.s01, this.s00, this.s11, this.s10);
};
XoroShiro128Plus.prototype.next = function () {
var nextRng = new XoroShiro128Plus(this.s01, this.s00, this.s11, this.s10);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
XoroShiro128Plus.prototype.unsafeNext = function () {
var out = (this.s00 + this.s10) | 0;
var a0 = this.s10 ^ this.s00;
var a1 = this.s11 ^ this.s01;
var s00 = this.s00;
var s01 = this.s01;
this.s00 = (s00 << 24) ^ (s01 >>> 8) ^ a0 ^ (a0 << 16);
this.s01 = (s01 << 24) ^ (s00 >>> 8) ^ a1 ^ ((a1 << 16) | (a0 >>> 16));
this.s10 = (a1 << 5) ^ (a0 >>> 27);
this.s11 = (a0 << 5) ^ (a1 >>> 27);
return out;
};
XoroShiro128Plus.prototype.jump = function () {
var nextRng = new XoroShiro128Plus(this.s01, this.s00, this.s11, this.s10);
nextRng.unsafeJump();
return nextRng;
};
XoroShiro128Plus.prototype.unsafeJump = function () {
var ns01 = 0;
var ns00 = 0;
var ns11 = 0;
var ns10 = 0;
var jump = [0xd8f554a5, 0xdf900294, 0x4b3201fc, 0x170865df];
for (var i = 0; i !== 4; ++i) {
for (var mask = 1; mask; mask <<= 1) {
if (jump[i] & mask) {
ns01 ^= this.s01;
ns00 ^= this.s00;
ns11 ^= this.s11;
ns10 ^= this.s10;
}
this.unsafeNext();
}
}
this.s01 = ns01;
this.s00 = ns00;
this.s11 = ns11;
this.s10 = ns10;
};
XoroShiro128Plus.prototype.getState = function () {
return [this.s01, this.s00, this.s11, this.s10];
};
return XoroShiro128Plus;
}());
function fromState(state) {
var valid = state.length === 4;
if (!valid) {
throw new Error('The state must have been produced by a xoroshiro128plus RandomGenerator');
}
return new XoroShiro128Plus(state[0], state[1], state[2], state[3]);
}
export var xoroshiro128plus = Object.assign(function (seed) {
return new XoroShiro128Plus(-1, ~seed, seed | 0, 0);
}, { fromState: fromState });

View File

@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@ -0,0 +1,15 @@
import { generateN, skipN, unsafeGenerateN, unsafeSkipN } from './generator/RandomGenerator.js';
import { congruential32 } from './generator/LinearCongruential.js';
import mersenne from './generator/MersenneTwister.js';
import { xorshift128plus } from './generator/XorShift.js';
import { xoroshiro128plus } from './generator/XoroShiro.js';
import { uniformArrayIntDistribution } from './distribution/UniformArrayIntDistribution.js';
import { uniformBigIntDistribution } from './distribution/UniformBigIntDistribution.js';
import { uniformIntDistribution } from './distribution/UniformIntDistribution.js';
import { unsafeUniformArrayIntDistribution } from './distribution/UnsafeUniformArrayIntDistribution.js';
import { unsafeUniformBigIntDistribution } from './distribution/UnsafeUniformBigIntDistribution.js';
import { unsafeUniformIntDistribution } from './distribution/UnsafeUniformIntDistribution.js';
var __type = 'module';
var __version = '6.1.0';
var __commitHash = 'a413dd2b721516be2ef29adffb515c5ae67bfbad';
export { __type, __version, __commitHash, generateN, skipN, unsafeGenerateN, unsafeSkipN, congruential32, mersenne, xorshift128plus, xoroshiro128plus, uniformArrayIntDistribution, uniformBigIntDistribution, uniformIntDistribution, unsafeUniformArrayIntDistribution, unsafeUniformBigIntDistribution, unsafeUniformIntDistribution, };

View File

@ -0,0 +1,3 @@
import * as prand from './pure-rand-default.js';
export default prand;
export * from './pure-rand-default.js';

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
export type Distribution<T> = (rng: RandomGenerator) => [T, RandomGenerator];

View File

@ -0,0 +1,6 @@
import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
declare function uniformArrayIntDistribution(from: ArrayInt, to: ArrayInt): Distribution<ArrayInt>;
declare function uniformArrayIntDistribution(from: ArrayInt, to: ArrayInt, rng: RandomGenerator): [ArrayInt, RandomGenerator];
export { uniformArrayIntDistribution };

View File

@ -0,0 +1,5 @@
import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
declare function uniformBigIntDistribution(from: bigint, to: bigint): Distribution<bigint>;
declare function uniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): [bigint, RandomGenerator];
export { uniformBigIntDistribution };

View File

@ -0,0 +1,5 @@
import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
declare function uniformIntDistribution(from: number, to: number): Distribution<number>;
declare function uniformIntDistribution(from: number, to: number, rng: RandomGenerator): [number, RandomGenerator];
export { uniformIntDistribution };

View File

@ -0,0 +1,3 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
export declare function unsafeUniformArrayIntDistribution(from: ArrayInt, to: ArrayInt, rng: RandomGenerator): ArrayInt;

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
export declare function unsafeUniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): bigint;

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
export declare function unsafeUniformIntDistribution(from: number, to: number, rng: RandomGenerator): number;

View File

@ -0,0 +1,13 @@
export type ArrayInt = {
sign: -1 | 1;
data: number[];
};
export declare function addArrayIntToNew(arrayIntA: ArrayInt, arrayIntB: ArrayInt): ArrayInt;
export declare function addOneToPositiveArrayInt(arrayInt: ArrayInt): ArrayInt;
export declare function substractArrayIntToNew(arrayIntA: ArrayInt, arrayIntB: ArrayInt): ArrayInt;
export declare function trimArrayIntInplace(arrayInt: ArrayInt): ArrayInt;
export type ArrayInt64 = Required<ArrayInt> & {
data: [number, number];
};
export declare function fromNumberToArrayInt64(out: ArrayInt64, n: number): ArrayInt64;
export declare function substractArrayInt64(out: ArrayInt64, arrayIntA: ArrayInt64, arrayIntB: ArrayInt64): ArrayInt64;

View File

@ -0,0 +1,3 @@
import { RandomGenerator } from '../../generator/RandomGenerator.js';
import { ArrayInt } from './ArrayInt.js';
export declare function unsafeUniformArrayIntDistributionInternal(out: ArrayInt['data'], rangeSize: ArrayInt['data'], rng: RandomGenerator): ArrayInt['data'];

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../../generator/RandomGenerator.js';
export declare function unsafeUniformIntDistributionInternal(rangeSize: number, rng: RandomGenerator): number;

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
export declare const congruential32: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export {};

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
declare const _default: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export default _default;

View File

@ -0,0 +1,12 @@
export interface RandomGenerator {
clone(): RandomGenerator;
next(): [number, RandomGenerator];
jump?(): RandomGenerator;
unsafeNext(): number;
unsafeJump?(): void;
getState?(): readonly number[];
}
export declare function unsafeGenerateN(rng: RandomGenerator, num: number): number[];
export declare function generateN(rng: RandomGenerator, num: number): [number[], RandomGenerator];
export declare function unsafeSkipN(rng: RandomGenerator, num: number): void;
export declare function skipN(rng: RandomGenerator, num: number): RandomGenerator;

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
export declare const xorshift128plus: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export {};

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
export declare const xoroshiro128plus: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export {};

View File

@ -0,0 +1,16 @@
import { RandomGenerator, generateN, skipN, unsafeGenerateN, unsafeSkipN } from './generator/RandomGenerator.js';
import { congruential32 } from './generator/LinearCongruential.js';
import mersenne from './generator/MersenneTwister.js';
import { xorshift128plus } from './generator/XorShift.js';
import { xoroshiro128plus } from './generator/XoroShiro.js';
import { Distribution } from './distribution/Distribution.js';
import { uniformArrayIntDistribution } from './distribution/UniformArrayIntDistribution.js';
import { uniformBigIntDistribution } from './distribution/UniformBigIntDistribution.js';
import { uniformIntDistribution } from './distribution/UniformIntDistribution.js';
import { unsafeUniformArrayIntDistribution } from './distribution/UnsafeUniformArrayIntDistribution.js';
import { unsafeUniformBigIntDistribution } from './distribution/UnsafeUniformBigIntDistribution.js';
import { unsafeUniformIntDistribution } from './distribution/UnsafeUniformIntDistribution.js';
declare const __type: string;
declare const __version: string;
declare const __commitHash: string;
export { __type, __version, __commitHash, RandomGenerator, generateN, skipN, unsafeGenerateN, unsafeSkipN, congruential32, mersenne, xorshift128plus, xoroshiro128plus, Distribution, uniformArrayIntDistribution, uniformBigIntDistribution, uniformIntDistribution, unsafeUniformArrayIntDistribution, unsafeUniformBigIntDistribution, unsafeUniformIntDistribution, };

View File

@ -0,0 +1,3 @@
import * as prand from './pure-rand-default.js';
export default prand;
export * from './pure-rand-default.js';

View File

@ -0,0 +1,50 @@
"use strict";
exports.__esModule = true;
exports.congruential32 = void 0;
var MULTIPLIER = 0x000343fd;
var INCREMENT = 0x00269ec3;
var MASK = 0xffffffff;
var MASK_2 = (1 << 31) - 1;
var computeNextSeed = function (seed) {
return (seed * MULTIPLIER + INCREMENT) & MASK;
};
var computeValueFromNextSeed = function (nextseed) {
return (nextseed & MASK_2) >> 16;
};
var LinearCongruential32 = (function () {
function LinearCongruential32(seed) {
this.seed = seed;
}
LinearCongruential32.prototype.clone = function () {
return new LinearCongruential32(this.seed);
};
LinearCongruential32.prototype.next = function () {
var nextRng = new LinearCongruential32(this.seed);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
LinearCongruential32.prototype.unsafeNext = function () {
var s1 = computeNextSeed(this.seed);
var v1 = computeValueFromNextSeed(s1);
var s2 = computeNextSeed(s1);
var v2 = computeValueFromNextSeed(s2);
this.seed = computeNextSeed(s2);
var v3 = computeValueFromNextSeed(this.seed);
var vnext = v3 + ((v2 + (v1 << 15)) << 15);
return vnext | 0;
};
LinearCongruential32.prototype.getState = function () {
return [this.seed];
};
return LinearCongruential32;
}());
function fromState(state) {
var valid = state.length === 1;
if (!valid) {
throw new Error('The state must have been produced by a congruential32 RandomGenerator');
}
return new LinearCongruential32(state[0]);
}
exports.congruential32 = Object.assign(function (seed) {
return new LinearCongruential32(seed);
}, { fromState: fromState });

View File

@ -0,0 +1,109 @@
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
exports.__esModule = true;
var MersenneTwister = (function () {
function MersenneTwister(states, index) {
this.states = states;
this.index = index;
}
MersenneTwister.twist = function (prev) {
var mt = prev.slice();
for (var idx = 0; idx !== MersenneTwister.N - MersenneTwister.M; ++idx) {
var y_1 = (mt[idx] & MersenneTwister.MASK_UPPER) + (mt[idx + 1] & MersenneTwister.MASK_LOWER);
mt[idx] = mt[idx + MersenneTwister.M] ^ (y_1 >>> 1) ^ (-(y_1 & 1) & MersenneTwister.A);
}
for (var idx = MersenneTwister.N - MersenneTwister.M; idx !== MersenneTwister.N - 1; ++idx) {
var y_2 = (mt[idx] & MersenneTwister.MASK_UPPER) + (mt[idx + 1] & MersenneTwister.MASK_LOWER);
mt[idx] = mt[idx + MersenneTwister.M - MersenneTwister.N] ^ (y_2 >>> 1) ^ (-(y_2 & 1) & MersenneTwister.A);
}
var y = (mt[MersenneTwister.N - 1] & MersenneTwister.MASK_UPPER) + (mt[0] & MersenneTwister.MASK_LOWER);
mt[MersenneTwister.N - 1] = mt[MersenneTwister.M - 1] ^ (y >>> 1) ^ (-(y & 1) & MersenneTwister.A);
return mt;
};
MersenneTwister.seeded = function (seed) {
var out = Array(MersenneTwister.N);
out[0] = seed;
for (var idx = 1; idx !== MersenneTwister.N; ++idx) {
var xored = out[idx - 1] ^ (out[idx - 1] >>> 30);
out[idx] = (Math.imul(MersenneTwister.F, xored) + idx) | 0;
}
return out;
};
MersenneTwister.from = function (seed) {
return new MersenneTwister(MersenneTwister.twist(MersenneTwister.seeded(seed)), 0);
};
MersenneTwister.prototype.clone = function () {
return new MersenneTwister(this.states, this.index);
};
MersenneTwister.prototype.next = function () {
var nextRng = new MersenneTwister(this.states, this.index);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
MersenneTwister.prototype.unsafeNext = function () {
var y = this.states[this.index];
y ^= this.states[this.index] >>> MersenneTwister.U;
y ^= (y << MersenneTwister.S) & MersenneTwister.B;
y ^= (y << MersenneTwister.T) & MersenneTwister.C;
y ^= y >>> MersenneTwister.L;
if (++this.index >= MersenneTwister.N) {
this.states = MersenneTwister.twist(this.states);
this.index = 0;
}
return y;
};
MersenneTwister.prototype.getState = function () {
return __spreadArray([this.index], __read(this.states), false);
};
MersenneTwister.fromState = function (state) {
var valid = state.length === MersenneTwister.N + 1 && state[0] >= 0 && state[0] < MersenneTwister.N;
if (!valid) {
throw new Error('The state must have been produced by a mersenne RandomGenerator');
}
return new MersenneTwister(state.slice(1), state[0]);
};
MersenneTwister.N = 624;
MersenneTwister.M = 397;
MersenneTwister.R = 31;
MersenneTwister.A = 0x9908b0df;
MersenneTwister.F = 1812433253;
MersenneTwister.U = 11;
MersenneTwister.S = 7;
MersenneTwister.B = 0x9d2c5680;
MersenneTwister.T = 15;
MersenneTwister.C = 0xefc60000;
MersenneTwister.L = 18;
MersenneTwister.MASK_LOWER = Math.pow(2, MersenneTwister.R) - 1;
MersenneTwister.MASK_UPPER = Math.pow(2, MersenneTwister.R);
return MersenneTwister;
}());
function fromState(state) {
return MersenneTwister.fromState(state);
}
exports["default"] = Object.assign(function (seed) {
return MersenneTwister.from(seed);
}, { fromState: fromState });

View File

@ -0,0 +1,29 @@
"use strict";
exports.__esModule = true;
exports.skipN = exports.unsafeSkipN = exports.generateN = exports.unsafeGenerateN = void 0;
function unsafeGenerateN(rng, num) {
var out = [];
for (var idx = 0; idx != num; ++idx) {
out.push(rng.unsafeNext());
}
return out;
}
exports.unsafeGenerateN = unsafeGenerateN;
function generateN(rng, num) {
var nextRng = rng.clone();
var out = unsafeGenerateN(nextRng, num);
return [out, nextRng];
}
exports.generateN = generateN;
function unsafeSkipN(rng, num) {
for (var idx = 0; idx != num; ++idx) {
rng.unsafeNext();
}
}
exports.unsafeSkipN = unsafeSkipN;
function skipN(rng, num) {
var nextRng = rng.clone();
unsafeSkipN(nextRng, num);
return nextRng;
}
exports.skipN = skipN;

View File

@ -0,0 +1,72 @@
"use strict";
exports.__esModule = true;
exports.xorshift128plus = void 0;
var XorShift128Plus = (function () {
function XorShift128Plus(s01, s00, s11, s10) {
this.s01 = s01;
this.s00 = s00;
this.s11 = s11;
this.s10 = s10;
}
XorShift128Plus.prototype.clone = function () {
return new XorShift128Plus(this.s01, this.s00, this.s11, this.s10);
};
XorShift128Plus.prototype.next = function () {
var nextRng = new XorShift128Plus(this.s01, this.s00, this.s11, this.s10);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
XorShift128Plus.prototype.unsafeNext = function () {
var a0 = this.s00 ^ (this.s00 << 23);
var a1 = this.s01 ^ ((this.s01 << 23) | (this.s00 >>> 9));
var b0 = a0 ^ this.s10 ^ ((a0 >>> 18) | (a1 << 14)) ^ ((this.s10 >>> 5) | (this.s11 << 27));
var b1 = a1 ^ this.s11 ^ (a1 >>> 18) ^ (this.s11 >>> 5);
var out = (this.s00 + this.s10) | 0;
this.s01 = this.s11;
this.s00 = this.s10;
this.s11 = b1;
this.s10 = b0;
return out;
};
XorShift128Plus.prototype.jump = function () {
var nextRng = new XorShift128Plus(this.s01, this.s00, this.s11, this.s10);
nextRng.unsafeJump();
return nextRng;
};
XorShift128Plus.prototype.unsafeJump = function () {
var ns01 = 0;
var ns00 = 0;
var ns11 = 0;
var ns10 = 0;
var jump = [0x635d2dff, 0x8a5cd789, 0x5c472f96, 0x121fd215];
for (var i = 0; i !== 4; ++i) {
for (var mask = 1; mask; mask <<= 1) {
if (jump[i] & mask) {
ns01 ^= this.s01;
ns00 ^= this.s00;
ns11 ^= this.s11;
ns10 ^= this.s10;
}
this.unsafeNext();
}
}
this.s01 = ns01;
this.s00 = ns00;
this.s11 = ns11;
this.s10 = ns10;
};
XorShift128Plus.prototype.getState = function () {
return [this.s01, this.s00, this.s11, this.s10];
};
return XorShift128Plus;
}());
function fromState(state) {
var valid = state.length === 4;
if (!valid) {
throw new Error('The state must have been produced by a xorshift128plus RandomGenerator');
}
return new XorShift128Plus(state[0], state[1], state[2], state[3]);
}
exports.xorshift128plus = Object.assign(function (seed) {
return new XorShift128Plus(-1, ~seed, seed | 0, 0);
}, { fromState: fromState });

View File

@ -0,0 +1,72 @@
"use strict";
exports.__esModule = true;
exports.xoroshiro128plus = void 0;
var XoroShiro128Plus = (function () {
function XoroShiro128Plus(s01, s00, s11, s10) {
this.s01 = s01;
this.s00 = s00;
this.s11 = s11;
this.s10 = s10;
}
XoroShiro128Plus.prototype.clone = function () {
return new XoroShiro128Plus(this.s01, this.s00, this.s11, this.s10);
};
XoroShiro128Plus.prototype.next = function () {
var nextRng = new XoroShiro128Plus(this.s01, this.s00, this.s11, this.s10);
var out = nextRng.unsafeNext();
return [out, nextRng];
};
XoroShiro128Plus.prototype.unsafeNext = function () {
var out = (this.s00 + this.s10) | 0;
var a0 = this.s10 ^ this.s00;
var a1 = this.s11 ^ this.s01;
var s00 = this.s00;
var s01 = this.s01;
this.s00 = (s00 << 24) ^ (s01 >>> 8) ^ a0 ^ (a0 << 16);
this.s01 = (s01 << 24) ^ (s00 >>> 8) ^ a1 ^ ((a1 << 16) | (a0 >>> 16));
this.s10 = (a1 << 5) ^ (a0 >>> 27);
this.s11 = (a0 << 5) ^ (a1 >>> 27);
return out;
};
XoroShiro128Plus.prototype.jump = function () {
var nextRng = new XoroShiro128Plus(this.s01, this.s00, this.s11, this.s10);
nextRng.unsafeJump();
return nextRng;
};
XoroShiro128Plus.prototype.unsafeJump = function () {
var ns01 = 0;
var ns00 = 0;
var ns11 = 0;
var ns10 = 0;
var jump = [0xd8f554a5, 0xdf900294, 0x4b3201fc, 0x170865df];
for (var i = 0; i !== 4; ++i) {
for (var mask = 1; mask; mask <<= 1) {
if (jump[i] & mask) {
ns01 ^= this.s01;
ns00 ^= this.s00;
ns11 ^= this.s11;
ns10 ^= this.s10;
}
this.unsafeNext();
}
}
this.s01 = ns01;
this.s00 = ns00;
this.s11 = ns11;
this.s10 = ns10;
};
XoroShiro128Plus.prototype.getState = function () {
return [this.s01, this.s00, this.s11, this.s10];
};
return XoroShiro128Plus;
}());
function fromState(state) {
var valid = state.length === 4;
if (!valid) {
throw new Error('The state must have been produced by a xoroshiro128plus RandomGenerator');
}
return new XoroShiro128Plus(state[0], state[1], state[2], state[3]);
}
exports.xoroshiro128plus = Object.assign(function (seed) {
return new XoroShiro128Plus(-1, ~seed, seed | 0, 0);
}, { fromState: fromState });

View File

@ -0,0 +1,34 @@
"use strict";
exports.__esModule = true;
exports.unsafeUniformIntDistribution = exports.unsafeUniformBigIntDistribution = exports.unsafeUniformArrayIntDistribution = exports.uniformIntDistribution = exports.uniformBigIntDistribution = exports.uniformArrayIntDistribution = exports.xoroshiro128plus = exports.xorshift128plus = exports.mersenne = exports.congruential32 = exports.unsafeSkipN = exports.unsafeGenerateN = exports.skipN = exports.generateN = exports.__commitHash = exports.__version = exports.__type = void 0;
var RandomGenerator_1 = require("./generator/RandomGenerator");
exports.generateN = RandomGenerator_1.generateN;
exports.skipN = RandomGenerator_1.skipN;
exports.unsafeGenerateN = RandomGenerator_1.unsafeGenerateN;
exports.unsafeSkipN = RandomGenerator_1.unsafeSkipN;
var LinearCongruential_1 = require("./generator/LinearCongruential");
exports.congruential32 = LinearCongruential_1.congruential32;
var MersenneTwister_1 = require("./generator/MersenneTwister");
exports.mersenne = MersenneTwister_1["default"];
var XorShift_1 = require("./generator/XorShift");
exports.xorshift128plus = XorShift_1.xorshift128plus;
var XoroShiro_1 = require("./generator/XoroShiro");
exports.xoroshiro128plus = XoroShiro_1.xoroshiro128plus;
var UniformArrayIntDistribution_1 = require("./distribution/UniformArrayIntDistribution");
exports.uniformArrayIntDistribution = UniformArrayIntDistribution_1.uniformArrayIntDistribution;
var UniformBigIntDistribution_1 = require("./distribution/UniformBigIntDistribution");
exports.uniformBigIntDistribution = UniformBigIntDistribution_1.uniformBigIntDistribution;
var UniformIntDistribution_1 = require("./distribution/UniformIntDistribution");
exports.uniformIntDistribution = UniformIntDistribution_1.uniformIntDistribution;
var UnsafeUniformArrayIntDistribution_1 = require("./distribution/UnsafeUniformArrayIntDistribution");
exports.unsafeUniformArrayIntDistribution = UnsafeUniformArrayIntDistribution_1.unsafeUniformArrayIntDistribution;
var UnsafeUniformBigIntDistribution_1 = require("./distribution/UnsafeUniformBigIntDistribution");
exports.unsafeUniformBigIntDistribution = UnsafeUniformBigIntDistribution_1.unsafeUniformBigIntDistribution;
var UnsafeUniformIntDistribution_1 = require("./distribution/UnsafeUniformIntDistribution");
exports.unsafeUniformIntDistribution = UnsafeUniformIntDistribution_1.unsafeUniformIntDistribution;
var __type = 'commonjs';
exports.__type = __type;
var __version = '6.1.0';
exports.__version = __version;
var __commitHash = 'a413dd2b721516be2ef29adffb515c5ae67bfbad';
exports.__commitHash = __commitHash;

View File

@ -0,0 +1,19 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
exports.__esModule = true;
var prand = require("./pure-rand-default");
exports["default"] = prand;
__exportStar(require("./pure-rand-default"), exports);

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
export type Distribution<T> = (rng: RandomGenerator) => [T, RandomGenerator];

View File

@ -0,0 +1,6 @@
import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
declare function uniformArrayIntDistribution(from: ArrayInt, to: ArrayInt): Distribution<ArrayInt>;
declare function uniformArrayIntDistribution(from: ArrayInt, to: ArrayInt, rng: RandomGenerator): [ArrayInt, RandomGenerator];
export { uniformArrayIntDistribution };

View File

@ -0,0 +1,5 @@
import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
declare function uniformBigIntDistribution(from: bigint, to: bigint): Distribution<bigint>;
declare function uniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): [bigint, RandomGenerator];
export { uniformBigIntDistribution };

View File

@ -0,0 +1,5 @@
import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
declare function uniformIntDistribution(from: number, to: number): Distribution<number>;
declare function uniformIntDistribution(from: number, to: number, rng: RandomGenerator): [number, RandomGenerator];
export { uniformIntDistribution };

View File

@ -0,0 +1,3 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
export declare function unsafeUniformArrayIntDistribution(from: ArrayInt, to: ArrayInt, rng: RandomGenerator): ArrayInt;

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
export declare function unsafeUniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): bigint;

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../generator/RandomGenerator.js';
export declare function unsafeUniformIntDistribution(from: number, to: number, rng: RandomGenerator): number;

View File

@ -0,0 +1,13 @@
export type ArrayInt = {
sign: -1 | 1;
data: number[];
};
export declare function addArrayIntToNew(arrayIntA: ArrayInt, arrayIntB: ArrayInt): ArrayInt;
export declare function addOneToPositiveArrayInt(arrayInt: ArrayInt): ArrayInt;
export declare function substractArrayIntToNew(arrayIntA: ArrayInt, arrayIntB: ArrayInt): ArrayInt;
export declare function trimArrayIntInplace(arrayInt: ArrayInt): ArrayInt;
export type ArrayInt64 = Required<ArrayInt> & {
data: [number, number];
};
export declare function fromNumberToArrayInt64(out: ArrayInt64, n: number): ArrayInt64;
export declare function substractArrayInt64(out: ArrayInt64, arrayIntA: ArrayInt64, arrayIntB: ArrayInt64): ArrayInt64;

View File

@ -0,0 +1,3 @@
import { RandomGenerator } from '../../generator/RandomGenerator.js';
import { ArrayInt } from './ArrayInt.js';
export declare function unsafeUniformArrayIntDistributionInternal(out: ArrayInt['data'], rangeSize: ArrayInt['data'], rng: RandomGenerator): ArrayInt['data'];

View File

@ -0,0 +1,2 @@
import { RandomGenerator } from '../../generator/RandomGenerator.js';
export declare function unsafeUniformIntDistributionInternal(rangeSize: number, rng: RandomGenerator): number;

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
export declare const congruential32: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export {};

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
declare const _default: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export default _default;

View File

@ -0,0 +1,12 @@
export interface RandomGenerator {
clone(): RandomGenerator;
next(): [number, RandomGenerator];
jump?(): RandomGenerator;
unsafeNext(): number;
unsafeJump?(): void;
getState?(): readonly number[];
}
export declare function unsafeGenerateN(rng: RandomGenerator, num: number): number[];
export declare function generateN(rng: RandomGenerator, num: number): [number[], RandomGenerator];
export declare function unsafeSkipN(rng: RandomGenerator, num: number): void;
export declare function skipN(rng: RandomGenerator, num: number): RandomGenerator;

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
export declare const xorshift128plus: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export {};

View File

@ -0,0 +1,6 @@
import { RandomGenerator } from './RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
export declare const xoroshiro128plus: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export {};

View File

@ -0,0 +1,16 @@
import { RandomGenerator, generateN, skipN, unsafeGenerateN, unsafeSkipN } from './generator/RandomGenerator.js';
import { congruential32 } from './generator/LinearCongruential.js';
import mersenne from './generator/MersenneTwister.js';
import { xorshift128plus } from './generator/XorShift.js';
import { xoroshiro128plus } from './generator/XoroShiro.js';
import { Distribution } from './distribution/Distribution.js';
import { uniformArrayIntDistribution } from './distribution/UniformArrayIntDistribution.js';
import { uniformBigIntDistribution } from './distribution/UniformBigIntDistribution.js';
import { uniformIntDistribution } from './distribution/UniformIntDistribution.js';
import { unsafeUniformArrayIntDistribution } from './distribution/UnsafeUniformArrayIntDistribution.js';
import { unsafeUniformBigIntDistribution } from './distribution/UnsafeUniformBigIntDistribution.js';
import { unsafeUniformIntDistribution } from './distribution/UnsafeUniformIntDistribution.js';
declare const __type: string;
declare const __version: string;
declare const __commitHash: string;
export { __type, __version, __commitHash, RandomGenerator, generateN, skipN, unsafeGenerateN, unsafeSkipN, congruential32, mersenne, xorshift128plus, xoroshiro128plus, Distribution, uniformArrayIntDistribution, uniformBigIntDistribution, uniformIntDistribution, unsafeUniformArrayIntDistribution, unsafeUniformBigIntDistribution, unsafeUniformIntDistribution, };

View File

@ -0,0 +1,3 @@
import * as prand from './pure-rand-default.js';
export default prand;
export * from './pure-rand-default.js';