New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pure-rand

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pure-rand - npm Package Compare versions

Comparing version 6.1.0 to 7.0.0

lib/distribution/GenerateN.js

94

CHANGELOG.md

@@ -1,94 +0,20 @@

# CHANGELOG 6.X
# CHANGELOG 7.X
## 6.1.0
## 7.0.0
### Features
- [c60c828](https://github.com/dubzzz/pure-rand/commit/c60c828) ✨ Clone from state on `xorshift128plus` (#697)
- [6a16bfe](https://github.com/dubzzz/pure-rand/commit/6a16bfe) ✨ Clone from state on `mersenne` (#698)
- [fb78e2d](https://github.com/dubzzz/pure-rand/commit/fb78e2d) ✨ Clone from state on `xoroshiro128plus` (#699)
- [a7dd56c](https://github.com/dubzzz/pure-rand/commit/a7dd56c) ✨ Clone from state on congruential32 (#696)
- [1f6c3a5](https://github.com/dubzzz/pure-rand/commit/1f6c3a5) 🏷️ Expose internal state of generators (#694)
### Fixes
- [30d439a](https://github.com/dubzzz/pure-rand/commit/30d439a) 💚 Fix broken lock file (#695)
- [9f935ae](https://github.com/dubzzz/pure-rand/commit/9f935ae) 👷 Speed-up CI with better cache (#677)
## 6.0.4
### Fixes
- [716e073](https://github.com/dubzzz/pure-rand/commit/716e073) 🐛 Fix typings for node native esm (#649)
## 6.0.3
### Fixes
- [9aca792](https://github.com/dubzzz/pure-rand/commit/9aca792) 🏷️ Better declare ESM's types (#634)
## 6.0.2
### Fixes
- [6d05e8f](https://github.com/dubzzz/pure-rand/commit/6d05e8f) 🔐 Sign published packages (#591)
- [8b4e165](https://github.com/dubzzz/pure-rand/commit/8b4e165) 👷 Switch default to Node 18 in CI (#578)
## 6.0.1
### Fixes
- [05421f2](https://github.com/dubzzz/pure-rand/commit/05421f2) 🚨 Reformat README.md (#563)
- [ffacfbd](https://github.com/dubzzz/pure-rand/commit/ffacfbd) 📝 Give simple seed computation example (#562)
- [e432d59](https://github.com/dubzzz/pure-rand/commit/e432d59) 📝 Add extra keywords (#561)
- [f5b18d4](https://github.com/dubzzz/pure-rand/commit/f5b18d4) 🐛 Declare types first for package (#560)
- [a5b30db](https://github.com/dubzzz/pure-rand/commit/a5b30db) 📝 Final clean-up of the README (#559)
- [5254ee0](https://github.com/dubzzz/pure-rand/commit/5254ee0) 📝 Fix simple examples not fully working (#558)
- [8daf460](https://github.com/dubzzz/pure-rand/commit/8daf460) 📝 Clarify the README (#556)
- [a915b6a](https://github.com/dubzzz/pure-rand/commit/a915b6a) 📝 Fix url error in README for logo (#554)
- [f94885c](https://github.com/dubzzz/pure-rand/commit/f94885c) 📝 Rework README header with logo (#553)
- [5f7645e](https://github.com/dubzzz/pure-rand/commit/5f7645e) 📝 Typo in link to comparison SVG (#551)
- [61726af](https://github.com/dubzzz/pure-rand/commit/61726af) 📝 Better keywords for NPM (#550)
- [6001e5a](https://github.com/dubzzz/pure-rand/commit/6001e5a) 📝 Update performance section with recent stats (#549)
- [556ec33](https://github.com/dubzzz/pure-rand/commit/556ec33) ⚗️ Rewrite not uniform of pure-rand (#547)
- [b3dfea5](https://github.com/dubzzz/pure-rand/commit/b3dfea5) ⚗️ Add more libraries to the experiment (#546)
- [ac8b85d](https://github.com/dubzzz/pure-rand/commit/ac8b85d) ⚗️ Add some more non-uniform versions (#543)
- [44af2ad](https://github.com/dubzzz/pure-rand/commit/44af2ad) ⚗️ Add some more self comparisons (#542)
- [6d3342d](https://github.com/dubzzz/pure-rand/commit/6d3342d) 📝 Add some more details on the algorithms in compare (#541)
- [359e214](https://github.com/dubzzz/pure-rand/commit/359e214) 📝 Fix some typos in README (#540)
- [28a7bfe](https://github.com/dubzzz/pure-rand/commit/28a7bfe) 📝 Document some performance stats (#539)
- [81860b7](https://github.com/dubzzz/pure-rand/commit/81860b7) ⚗️ Measure performance against other libraries (#538)
- [114c2c7](https://github.com/dubzzz/pure-rand/commit/114c2c7) 📝 Publish changelogs from 3.X to 6.X (#537)
## 6.0.0
### Breaking Changes
- [c45912f](https://github.com/dubzzz/pure-rand/commit/c45912f) 💥 Require generators uniform in int32 (#513)
- [0bde03e](https://github.com/dubzzz/pure-rand/commit/0bde03e) 💥 Drop congruencial generator (#511)
- [2c94832](https://github.com/dubzzz/pure-rand/commit/2c94832) 🏷️ Move to "import type" when feasible (#736)
- [3741a63](https://github.com/dubzzz/pure-rand/commit/3741a63) 🏷️ Mark `getState` as compulsory on `RandomGenerator` (#733)
### Features
- [7587984](https://github.com/dubzzz/pure-rand/commit/7587984) ⚡️ Faster uniform distribution on bigint (#517)
- [464960a](https://github.com/dubzzz/pure-rand/commit/464960a) ⚡️ Faster uniform distribution on small ranges (#516)
- [b4852a8](https://github.com/dubzzz/pure-rand/commit/b4852a8) ⚡️ Faster Congruencial 32bits (#512)
- [fdb6ec8](https://github.com/dubzzz/pure-rand/commit/fdb6ec8) ⚡️ Faster Mersenne-Twister (#510)
- [bb69be5](https://github.com/dubzzz/pure-rand/commit/bb69be5) ⚡️ Drop infinite loop for explicit loop (#507)
- [228c73d](https://github.com/dubzzz/pure-rand/commit/228c73d) ⚡️ Faster uniform distributions on bigint (#757)
- [86869a1](https://github.com/dubzzz/pure-rand/commit/86869a1) ✨ Expose generators and distributions (#735)
### Fixes
- [00fc62b](https://github.com/dubzzz/pure-rand/commit/00fc62b) 🔨 Add missing benchType to the script (#522)
- [db4a0a6](https://github.com/dubzzz/pure-rand/commit/db4a0a6) 🔨 Add more options to benchmark (#521)
- [5c1ca0e](https://github.com/dubzzz/pure-rand/commit/5c1ca0e) 🔨 Fix typo in benchmark code (#520)
- [36c965f](https://github.com/dubzzz/pure-rand/commit/36c965f) 👷 Define a benchmark workflow (#519)
- [0281cfd](https://github.com/dubzzz/pure-rand/commit/0281cfd) 🔨 More customizable benchmark (#518)
- [a7e19a8](https://github.com/dubzzz/pure-rand/commit/a7e19a8) 🔥 Clean internals of uniform distribution (#515)
- [520cca7](https://github.com/dubzzz/pure-rand/commit/520cca7) 🔨 Add some more benchmarks (#514)
- [c2d6ee6](https://github.com/dubzzz/pure-rand/commit/c2d6ee6) 🔨 Fix typo in bench for large reference (#509)
- [2dd7280](https://github.com/dubzzz/pure-rand/commit/2dd7280) 🔥 Clean useless variable (#506)
- [dd621c9](https://github.com/dubzzz/pure-rand/commit/dd621c9) 🔨 Adapt benchmarks to make them reliable (#505)
- [122f968](https://github.com/dubzzz/pure-rand/commit/122f968) 👷 Drop dependabot
- [f11d2e8](https://github.com/dubzzz/pure-rand/commit/f11d2e8) 💸 Add GitHub sponsors in repository's configuration
- [6a23e48](https://github.com/dubzzz/pure-rand/commit/6a23e48) 👷 Stop running tests against node 12 (#486)
- [cbefd3e](https://github.com/dubzzz/pure-rand/commit/cbefd3e) 🔧 Better configuration of prettier (#474)
- [c6712d3](https://github.com/dubzzz/pure-rand/commit/c6712d3) 🔧 Configure Renovate (#470)
- [680a672](https://github.com/dubzzz/pure-rand/commit/680a672) 🚚 Do not export mersenne as default (#738)
- [e1758c0](https://github.com/dubzzz/pure-rand/commit/e1758c0) 🚚 Split ArrayInt into two files (#737)
- [0c356cf](https://github.com/dubzzz/pure-rand/commit/0c356cf) 🚚 Moving files around (#734)
- [6d9b7b4](https://github.com/dubzzz/pure-rand/commit/6d9b7b4) 📝 Document generation of float/double (#715)
"use strict";
exports.__esModule = true;
exports.substractArrayInt64 = exports.fromNumberToArrayInt64 = exports.trimArrayIntInplace = exports.substractArrayIntToNew = exports.addOneToPositiveArrayInt = exports.addArrayIntToNew = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addArrayIntToNew = addArrayIntToNew;
exports.addOneToPositiveArrayInt = addOneToPositiveArrayInt;
exports.substractArrayIntToNew = substractArrayIntToNew;
exports.trimArrayIntInplace = trimArrayIntInplace;
function addArrayIntToNew(arrayIntA, arrayIntB) {

@@ -24,3 +27,2 @@ if (arrayIntA.sign !== arrayIntB.sign) {

}
exports.addArrayIntToNew = addArrayIntToNew;
function addOneToPositiveArrayInt(arrayInt) {

@@ -41,3 +43,2 @@ arrayInt.sign = 1;

}
exports.addOneToPositiveArrayInt = addOneToPositiveArrayInt;
function isStrictlySmaller(dataA, dataB) {

@@ -79,3 +80,2 @@ var maxLength = Math.max(dataA.length, dataB.length);

}
exports.substractArrayIntToNew = substractArrayIntToNew;
function trimArrayIntInplace(arrayInt) {

@@ -93,53 +93,1 @@ var data = arrayInt.data;

}
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;
"use strict";
exports.__esModule = true;
exports.unsafeUniformArrayIntDistributionInternal = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unsafeUniformArrayIntDistributionInternal = unsafeUniformArrayIntDistributionInternal;
var UnsafeUniformIntDistributionInternal_1 = require("./UnsafeUniformIntDistributionInternal");

@@ -25,2 +25,1 @@ function unsafeUniformArrayIntDistributionInternal(out, rangeSize, rng) {

}
exports.unsafeUniformArrayIntDistributionInternal = unsafeUniformArrayIntDistributionInternal;
"use strict";
exports.__esModule = true;
exports.unsafeUniformIntDistributionInternal = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unsafeUniformIntDistributionInternal = unsafeUniformIntDistributionInternal;
function unsafeUniformIntDistributionInternal(rangeSize, rng) {

@@ -12,2 +12,1 @@ var MaxAllowed = rangeSize > 2 ? ~~(0x100000000 / rangeSize) * rangeSize : 0x100000000;

}
exports.unsafeUniformIntDistributionInternal = unsafeUniformIntDistributionInternal;
"use strict";
exports.__esModule = true;
exports.uniformArrayIntDistribution = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniformArrayIntDistribution = uniformArrayIntDistribution;
var UnsafeUniformArrayIntDistribution_1 = require("./UnsafeUniformArrayIntDistribution");

@@ -15,2 +15,1 @@ function uniformArrayIntDistribution(from, to, rng) {

}
exports.uniformArrayIntDistribution = uniformArrayIntDistribution;
"use strict";
exports.__esModule = true;
exports.uniformBigIntDistribution = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniformBigIntDistribution = uniformBigIntDistribution;
var UnsafeUniformBigIntDistribution_1 = require("./UnsafeUniformBigIntDistribution");

@@ -15,2 +15,1 @@ function uniformBigIntDistribution(from, to, rng) {

}
exports.uniformBigIntDistribution = uniformBigIntDistribution;
"use strict";
exports.__esModule = true;
exports.uniformIntDistribution = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniformIntDistribution = uniformIntDistribution;
var UnsafeUniformIntDistribution_1 = require("./UnsafeUniformIntDistribution");

@@ -15,2 +15,1 @@ function uniformIntDistribution(from, to, rng) {

}
exports.uniformIntDistribution = uniformIntDistribution;
"use strict";
exports.__esModule = true;
exports.unsafeUniformArrayIntDistribution = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unsafeUniformArrayIntDistribution = unsafeUniformArrayIntDistribution;
var ArrayInt_1 = require("./internals/ArrayInt");

@@ -12,2 +12,1 @@ var UnsafeUniformArrayIntDistributionInternal_1 = require("./internals/UnsafeUniformArrayIntDistributionInternal");

}
exports.unsafeUniformArrayIntDistribution = unsafeUniformArrayIntDistribution;
"use strict";
exports.__esModule = true;
exports.unsafeUniformBigIntDistribution = void 0;
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 + SBigInt(1);
var MinRng = SBigInt(-0x80000000);
var NumValues = SBigInt(0x100000000);
var diff = to - from + One;
var FinalNumValues = NumValues;
var NumIterations = 1;
while (FinalNumValues < diff) {
FinalNumValues *= NumValues;
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 (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;
}
while (value >= MaxAcceptedRandom) {
value = generateNext(NumIterations, rng);
}
return (value % diff) + from;
}
exports.unsafeUniformBigIntDistribution = unsafeUniformBigIntDistribution;
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;
}
"use strict";
exports.__esModule = true;
exports.unsafeUniformIntDistribution = void 0;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unsafeUniformIntDistribution = unsafeUniformIntDistribution;
var UnsafeUniformIntDistributionInternal_1 = require("./internals/UnsafeUniformIntDistributionInternal");
var ArrayInt_1 = require("./internals/ArrayInt");
var ArrayInt64_1 = require("./internals/ArrayInt64");
var UnsafeUniformArrayIntDistributionInternal_1 = require("./internals/UnsafeUniformArrayIntDistributionInternal");

@@ -14,4 +14,4 @@ var safeNumberMaxSafeInteger = Number.MAX_SAFE_INTEGER;

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));
? (0, ArrayInt64_1.fromNumberToArrayInt64)(sharedC, rangeSize)
: (0, ArrayInt64_1.substractArrayInt64)(sharedC, (0, ArrayInt64_1.fromNumberToArrayInt64)(sharedA, to), (0, ArrayInt64_1.fromNumberToArrayInt64)(sharedB, from));
if (rangeSizeArrayIntValue.data[1] === 0xffffffff) {

@@ -35,2 +35,1 @@ rangeSizeArrayIntValue.data[0] += 1;

}
exports.unsafeUniformIntDistribution = unsafeUniformIntDistribution;

@@ -84,50 +84,1 @@ export function addArrayIntToNew(arrayIntA, arrayIntB) {

}
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;
}
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;
export function unsafeUniformBigIntDistribution(from, to, rng) {
var diff = to - from + SBigInt(1);
var MinRng = SBigInt(-0x80000000);
var NumValues = SBigInt(0x100000000);
var diff = to - from + One;
var FinalNumValues = NumValues;
var NumIterations = 1;
while (FinalNumValues < diff) {
FinalNumValues *= NumValues;
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 (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;
}
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;
}
import { unsafeUniformIntDistributionInternal } from './internals/UnsafeUniformIntDistributionInternal.js';
import { fromNumberToArrayInt64, substractArrayInt64 } from './internals/ArrayInt.js';
import { fromNumberToArrayInt64, substractArrayInt64 } from './internals/ArrayInt64.js';
import { unsafeUniformArrayIntDistributionInternal } from './internals/UnsafeUniformArrayIntDistributionInternal.js';

@@ -4,0 +4,0 @@ var safeNumberMaxSafeInteger = Number.MAX_SAFE_INTEGER;

@@ -105,4 +105,4 @@ var __read = (this && this.__read) || function (o, n) {

}
export default Object.assign(function (seed) {
export var mersenne = Object.assign(function (seed) {
return MersenneTwister.from(seed);
}, { fromState: fromState });

@@ -1,4 +0,3 @@

import { generateN, skipN, unsafeGenerateN, unsafeSkipN } from './generator/RandomGenerator.js';
import { congruential32 } from './generator/LinearCongruential.js';
import mersenne from './generator/MersenneTwister.js';
import { mersenne } from './generator/MersenneTwister.js';
import { xorshift128plus } from './generator/XorShift.js';

@@ -12,5 +11,9 @@ import { xoroshiro128plus } from './generator/XoroShiro.js';

import { unsafeUniformIntDistribution } from './distribution/UnsafeUniformIntDistribution.js';
import { skipN } from './distribution/SkipN.js';
import { generateN } from './distribution/GenerateN.js';
import { unsafeGenerateN } from './distribution/UnsafeGenerateN.js';
import { unsafeSkipN } from './distribution/UnsafeSkipN.js';
var __type = 'module';
var __version = '6.1.0';
var __commitHash = 'a413dd2b721516be2ef29adffb515c5ae67bfbad';
var __version = '7.0.0';
var __commitHash = 'a2db85918869e4a0e7b0c305ab2243cd22fe57c5';
export { __type, __version, __commitHash, generateN, skipN, unsafeGenerateN, unsafeSkipN, congruential32, mersenne, xorshift128plus, xoroshiro128plus, uniformArrayIntDistribution, uniformBigIntDistribution, uniformIntDistribution, unsafeUniformArrayIntDistribution, unsafeUniformBigIntDistribution, unsafeUniformIntDistribution, };

@@ -9,6 +9,1 @@ export type 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;

@@ -1,3 +0,3 @@

import { RandomGenerator } from '../../generator/RandomGenerator.js';
import { ArrayInt } from './ArrayInt.js';
import type { RandomGenerator } from '../../types/RandomGenerator.js';
import type { ArrayInt } from './ArrayInt.js';
export declare function unsafeUniformArrayIntDistributionInternal(out: ArrayInt['data'], rangeSize: ArrayInt['data'], rng: RandomGenerator): ArrayInt['data'];

@@ -1,2 +0,2 @@

import { RandomGenerator } from '../../generator/RandomGenerator.js';
import type { RandomGenerator } from '../../types/RandomGenerator.js';
export declare function unsafeUniformIntDistributionInternal(rangeSize: number, rng: RandomGenerator): number;

@@ -1,6 +0,6 @@

import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
import type { Distribution } from '../types/Distribution.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
import type { 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 };

@@ -1,5 +0,5 @@

import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { Distribution } from '../types/Distribution.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function uniformBigIntDistribution(from: bigint, to: bigint): Distribution<bigint>;
declare function uniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): [bigint, RandomGenerator];
export { uniformBigIntDistribution };

@@ -1,5 +0,5 @@

import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { Distribution } from '../types/Distribution.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function uniformIntDistribution(from: number, to: number): Distribution<number>;
declare function uniformIntDistribution(from: number, to: number, rng: RandomGenerator): [number, RandomGenerator];
export { uniformIntDistribution };

@@ -1,3 +0,3 @@

import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
import type { ArrayInt } from './internals/ArrayInt.js';
export declare function unsafeUniformArrayIntDistribution(from: ArrayInt, to: ArrayInt, rng: RandomGenerator): ArrayInt;

@@ -1,2 +0,2 @@

import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
export declare function unsafeUniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): bigint;

@@ -1,2 +0,2 @@

import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
export declare function unsafeUniformIntDistribution(from: number, to: number, rng: RandomGenerator): number;

@@ -1,2 +0,2 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;

@@ -3,0 +3,0 @@ export declare const congruential32: ((seed: number) => RandomGenerator) & {

@@ -1,6 +0,6 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
declare const _default: ((seed: number) => RandomGenerator) & {
export declare const mersenne: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export default _default;
export {};

@@ -1,2 +0,2 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;

@@ -3,0 +3,0 @@ export declare const xoroshiro128plus: ((seed: number) => RandomGenerator) & {

@@ -1,2 +0,2 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;

@@ -3,0 +3,0 @@ export declare const xorshift128plus: ((seed: number) => RandomGenerator) & {

@@ -1,7 +0,7 @@

import { RandomGenerator, generateN, skipN, unsafeGenerateN, unsafeSkipN } from './generator/RandomGenerator.js';
import type { RandomGenerator } from './types/RandomGenerator.js';
import { congruential32 } from './generator/LinearCongruential.js';
import mersenne from './generator/MersenneTwister.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 type { Distribution } from './types/Distribution.js';
import { uniformArrayIntDistribution } from './distribution/UniformArrayIntDistribution.js';

@@ -13,2 +13,6 @@ import { uniformBigIntDistribution } from './distribution/UniformBigIntDistribution.js';

import { unsafeUniformIntDistribution } from './distribution/UnsafeUniformIntDistribution.js';
import { skipN } from './distribution/SkipN.js';
import { generateN } from './distribution/GenerateN.js';
import { unsafeGenerateN } from './distribution/UnsafeGenerateN.js';
import { unsafeSkipN } from './distribution/UnsafeSkipN.js';
declare const __type: string;

@@ -15,0 +19,0 @@ declare const __version: string;

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.congruential32 = void 0;

@@ -4,0 +4,0 @@ var MULTIPLIER = 0x000343fd;

@@ -27,3 +27,4 @@ "use strict";

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mersenne = void 0;
var MersenneTwister = (function () {

@@ -108,4 +109,4 @@ function MersenneTwister(states, index) {

}
exports["default"] = Object.assign(function (seed) {
exports.mersenne = Object.assign(function (seed) {
return MersenneTwister.from(seed);
}, { fromState: fromState });
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.xoroshiro128plus = void 0;

@@ -4,0 +4,0 @@ var XoroShiro128Plus = (function () {

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.xorshift128plus = void 0;

@@ -4,0 +4,0 @@ var XorShift128Plus = (function () {

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: 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;
Object.defineProperty(exports, "congruential32", { enumerable: true, get: function () { return LinearCongruential_1.congruential32; } });
var MersenneTwister_1 = require("./generator/MersenneTwister");
exports.mersenne = MersenneTwister_1["default"];
Object.defineProperty(exports, "mersenne", { enumerable: true, get: function () { return MersenneTwister_1.mersenne; } });
var XorShift_1 = require("./generator/XorShift");
exports.xorshift128plus = XorShift_1.xorshift128plus;
Object.defineProperty(exports, "xorshift128plus", { enumerable: true, get: function () { return XorShift_1.xorshift128plus; } });
var XoroShiro_1 = require("./generator/XoroShiro");
exports.xoroshiro128plus = XoroShiro_1.xoroshiro128plus;
Object.defineProperty(exports, "xoroshiro128plus", { enumerable: true, get: function () { return XoroShiro_1.xoroshiro128plus; } });
var UniformArrayIntDistribution_1 = require("./distribution/UniformArrayIntDistribution");
exports.uniformArrayIntDistribution = UniformArrayIntDistribution_1.uniformArrayIntDistribution;
Object.defineProperty(exports, "uniformArrayIntDistribution", { enumerable: true, get: function () { return UniformArrayIntDistribution_1.uniformArrayIntDistribution; } });
var UniformBigIntDistribution_1 = require("./distribution/UniformBigIntDistribution");
exports.uniformBigIntDistribution = UniformBigIntDistribution_1.uniformBigIntDistribution;
Object.defineProperty(exports, "uniformBigIntDistribution", { enumerable: true, get: function () { return UniformBigIntDistribution_1.uniformBigIntDistribution; } });
var UniformIntDistribution_1 = require("./distribution/UniformIntDistribution");
exports.uniformIntDistribution = UniformIntDistribution_1.uniformIntDistribution;
Object.defineProperty(exports, "uniformIntDistribution", { enumerable: true, get: function () { return UniformIntDistribution_1.uniformIntDistribution; } });
var UnsafeUniformArrayIntDistribution_1 = require("./distribution/UnsafeUniformArrayIntDistribution");
exports.unsafeUniformArrayIntDistribution = UnsafeUniformArrayIntDistribution_1.unsafeUniformArrayIntDistribution;
Object.defineProperty(exports, "unsafeUniformArrayIntDistribution", { enumerable: true, get: function () { return UnsafeUniformArrayIntDistribution_1.unsafeUniformArrayIntDistribution; } });
var UnsafeUniformBigIntDistribution_1 = require("./distribution/UnsafeUniformBigIntDistribution");
exports.unsafeUniformBigIntDistribution = UnsafeUniformBigIntDistribution_1.unsafeUniformBigIntDistribution;
Object.defineProperty(exports, "unsafeUniformBigIntDistribution", { enumerable: true, get: function () { return UnsafeUniformBigIntDistribution_1.unsafeUniformBigIntDistribution; } });
var UnsafeUniformIntDistribution_1 = require("./distribution/UnsafeUniformIntDistribution");
exports.unsafeUniformIntDistribution = UnsafeUniformIntDistribution_1.unsafeUniformIntDistribution;
Object.defineProperty(exports, "unsafeUniformIntDistribution", { enumerable: true, get: function () { return UnsafeUniformIntDistribution_1.unsafeUniformIntDistribution; } });
var SkipN_1 = require("./distribution/SkipN");
Object.defineProperty(exports, "skipN", { enumerable: true, get: function () { return SkipN_1.skipN; } });
var GenerateN_1 = require("./distribution/GenerateN");
Object.defineProperty(exports, "generateN", { enumerable: true, get: function () { return GenerateN_1.generateN; } });
var UnsafeGenerateN_1 = require("./distribution/UnsafeGenerateN");
Object.defineProperty(exports, "unsafeGenerateN", { enumerable: true, get: function () { return UnsafeGenerateN_1.unsafeGenerateN; } });
var UnsafeSkipN_1 = require("./distribution/UnsafeSkipN");
Object.defineProperty(exports, "unsafeSkipN", { enumerable: true, get: function () { return UnsafeSkipN_1.unsafeSkipN; } });
var __type = 'commonjs';
exports.__type = __type;
var __version = '6.1.0';
var __version = '7.0.0';
exports.__version = __version;
var __commitHash = 'a413dd2b721516be2ef29adffb515c5ae67bfbad';
var __commitHash = 'a2db85918869e4a0e7b0c305ab2243cd22fe57c5';
exports.__commitHash = __commitHash;

@@ -16,5 +16,5 @@ "use strict";

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
var prand = require("./pure-rand-default");
exports["default"] = prand;
exports.default = prand;
__exportStar(require("./pure-rand-default"), exports);

@@ -9,6 +9,1 @@ export type 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;

@@ -1,3 +0,3 @@

import { RandomGenerator } from '../../generator/RandomGenerator.js';
import { ArrayInt } from './ArrayInt.js';
import type { RandomGenerator } from '../../types/RandomGenerator.js';
import type { ArrayInt } from './ArrayInt.js';
export declare function unsafeUniformArrayIntDistributionInternal(out: ArrayInt['data'], rangeSize: ArrayInt['data'], rng: RandomGenerator): ArrayInt['data'];

@@ -1,2 +0,2 @@

import { RandomGenerator } from '../../generator/RandomGenerator.js';
import type { RandomGenerator } from '../../types/RandomGenerator.js';
export declare function unsafeUniformIntDistributionInternal(rangeSize: number, rng: RandomGenerator): number;

@@ -1,6 +0,6 @@

import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
import type { Distribution } from '../types/Distribution.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
import type { 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 };

@@ -1,5 +0,5 @@

import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { Distribution } from '../types/Distribution.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function uniformBigIntDistribution(from: bigint, to: bigint): Distribution<bigint>;
declare function uniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): [bigint, RandomGenerator];
export { uniformBigIntDistribution };

@@ -1,5 +0,5 @@

import { Distribution } from './Distribution.js';
import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { Distribution } from '../types/Distribution.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function uniformIntDistribution(from: number, to: number): Distribution<number>;
declare function uniformIntDistribution(from: number, to: number, rng: RandomGenerator): [number, RandomGenerator];
export { uniformIntDistribution };

@@ -1,3 +0,3 @@

import { RandomGenerator } from '../generator/RandomGenerator.js';
import { ArrayInt } from './internals/ArrayInt.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
import type { ArrayInt } from './internals/ArrayInt.js';
export declare function unsafeUniformArrayIntDistribution(from: ArrayInt, to: ArrayInt, rng: RandomGenerator): ArrayInt;

@@ -1,2 +0,2 @@

import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
export declare function unsafeUniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): bigint;

@@ -1,2 +0,2 @@

import { RandomGenerator } from '../generator/RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
export declare function unsafeUniformIntDistribution(from: number, to: number, rng: RandomGenerator): number;

@@ -1,2 +0,2 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;

@@ -3,0 +3,0 @@ export declare const congruential32: ((seed: number) => RandomGenerator) & {

@@ -1,6 +0,6 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;
declare const _default: ((seed: number) => RandomGenerator) & {
export declare const mersenne: ((seed: number) => RandomGenerator) & {
fromState: typeof fromState;
};
export default _default;
export {};

@@ -1,2 +0,2 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;

@@ -3,0 +3,0 @@ export declare const xoroshiro128plus: ((seed: number) => RandomGenerator) & {

@@ -1,2 +0,2 @@

import { RandomGenerator } from './RandomGenerator.js';
import type { RandomGenerator } from '../types/RandomGenerator.js';
declare function fromState(state: readonly number[]): RandomGenerator;

@@ -3,0 +3,0 @@ export declare const xorshift128plus: ((seed: number) => RandomGenerator) & {

@@ -1,7 +0,7 @@

import { RandomGenerator, generateN, skipN, unsafeGenerateN, unsafeSkipN } from './generator/RandomGenerator.js';
import type { RandomGenerator } from './types/RandomGenerator.js';
import { congruential32 } from './generator/LinearCongruential.js';
import mersenne from './generator/MersenneTwister.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 type { Distribution } from './types/Distribution.js';
import { uniformArrayIntDistribution } from './distribution/UniformArrayIntDistribution.js';

@@ -13,2 +13,6 @@ import { uniformBigIntDistribution } from './distribution/UniformBigIntDistribution.js';

import { unsafeUniformIntDistribution } from './distribution/UnsafeUniformIntDistribution.js';
import { skipN } from './distribution/SkipN.js';
import { generateN } from './distribution/GenerateN.js';
import { unsafeGenerateN } from './distribution/UnsafeGenerateN.js';
import { unsafeSkipN } from './distribution/UnsafeSkipN.js';
declare const __type: string;

@@ -15,0 +19,0 @@ declare const __version: string;

{
"name": "pure-rand",
"version": "6.1.0",
"version": "7.0.0",
"description": " Pure random number generator written in TypeScript",

@@ -20,2 +20,32 @@ "type": "commonjs",

},
"./distribution/*": {
"require": {
"types": "./lib/types/distribution/*.d.ts",
"default": "./lib/distribution/*.js"
},
"import": {
"types": "./lib/esm/types/distribution/*.d.ts",
"default": "./lib/esm/distribution/*.js"
}
},
"./generator/*": {
"require": {
"types": "./lib/types/generator/*.d.ts",
"default": "./lib/generator/*.js"
},
"import": {
"types": "./lib/esm/types/generator/*.d.ts",
"default": "./lib/esm/generator/*.js"
}
},
"./types/*": {
"require": {
"types": "./lib/types/types/*.d.ts",
"default": "./lib/types/*.js"
},
"import": {
"types": "./lib/esm/types/types/*.d.ts",
"default": "./lib/esm/types/*.js"
}
},
"module": "lib/esm/pure-rand.js",

@@ -27,3 +57,3 @@ "types": "lib/types/pure-rand.d.ts",

"sideEffects": false,
"packageManager": "yarn@4.1.1",
"packageManager": "yarn@4.5.3",
"scripts": {

@@ -52,14 +82,14 @@ "format:check": "prettier --list-different .",

"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.11.30",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.1",
"cross-env": "^7.0.3",
"fast-check": "^3.16.0",
"fast-check": "^3.23.1",
"jest": "^29.7.0",
"prettier": "3.2.5",
"replace-in-file": "^7.1.0",
"prettier": "3.4.1",
"replace-in-file": "^7.2.0",
"source-map-support": "^0.5.21",
"tinybench": "^2.6.0",
"ts-jest": "^29.1.2",
"tinybench": "^2.9.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.4.2"
"typescript": "^5.5.3"
},

@@ -66,0 +96,0 @@ "keywords": [

@@ -14,2 +14,3 @@ <h1>

[![Snyk Package Quality](https://snyk.io/advisor/npm-package/pure-rand/badge.svg)](https://snyk.io/advisor/npm-package/pure-rand)
[![Tested with fast-check](https://img.shields.io/badge/tested%20with-fast%E2%80%91check%20%F0%9F%90%92-%23282ea9?style=flat&logoSize=auto&labelColor=%231b1b1d)](https://fast-check.dev/)

@@ -210,1 +211,44 @@ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dubzzz/pure-rand/labels/good%20first%20issue)

(3) — While most users don't really think of it, uniform distribution is key! Without it entries might be biased towards some values and make some others less probable. The naive `rand() % numValues` is a good example of biased version as if `rand()` is uniform in `0, 1, 2` and `numValues` is `2`, the probabilities are: `P(0) = 67%`, `P(1) = 33%` causing `1` to be less probable than `0`
## Advanced patterns
### Generate 32-bit floating point numbers
The following snippet is responsible for generating 32-bit floating point numbers that spread uniformly between 0 (included) and 1 (excluded).
```js
import prand from 'pure-rand';
function generateFloat32(rng) {
const g1 = prand.unsafeUniformIntDistribution(0, (1 << 24) - 1, rng);
const value = g1 / (1 << 24);
return value;
}
const seed = 42;
const rng = prand.xoroshiro128plus(seed);
const float32Bits1 = generateFloat32(rng);
const float32Bits2 = generateFloat32(rng);
```
### Generate 64-bit floating point numbers
The following snippet is responsible for generating 64-bit floating point numbers that spread uniformly between 0 (included) and 1 (excluded).
```js
import prand from 'pure-rand';
function generateFloat64(rng) {
const g1 = prand.unsafeUniformIntDistribution(0, (1 << 26) - 1, rng);
const g2 = prand.unsafeUniformIntDistribution(0, (1 << 27) - 1, rng);
const value = (g1 * Math.pow(2, 27) + g2) * Math.pow(2, -53);
return value;
}
const seed = 42;
const rng = prand.xoroshiro128plus(seed);
const float64Bits1 = generateFloat64(rng);
const float64Bits2 = generateFloat64(rng);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc