pure-rand
Advanced tools
Comparing version 6.0.4 to 6.1.0
# CHANGELOG 6.X | ||
## 6.1.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 | ||
@@ -4,0 +19,0 @@ |
@@ -33,6 +33,16 @@ var MULTIPLIER = 0x000343fd; | ||
}; | ||
LinearCongruential32.prototype.getState = function () { | ||
return [this.seed]; | ||
}; | ||
return LinearCongruential32; | ||
}()); | ||
export var congruential32 = function (seed) { | ||
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 }); |
@@ -0,1 +1,26 @@ | ||
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 () { | ||
@@ -52,2 +77,12 @@ function MersenneTwister(states, index) { | ||
}; | ||
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; | ||
@@ -68,4 +103,7 @@ MersenneTwister.M = 397; | ||
}()); | ||
export default function (seed) { | ||
function fromState(state) { | ||
return MersenneTwister.fromState(state); | ||
} | ||
export default Object.assign(function (seed) { | ||
return MersenneTwister.from(seed); | ||
} | ||
}, { fromState: fromState }); |
@@ -55,6 +55,16 @@ var XoroShiro128Plus = (function () { | ||
}; | ||
XoroShiro128Plus.prototype.getState = function () { | ||
return [this.s01, this.s00, this.s11, this.s10]; | ||
}; | ||
return XoroShiro128Plus; | ||
}()); | ||
export var xoroshiro128plus = function (seed) { | ||
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 }); |
@@ -55,6 +55,16 @@ var XorShift128Plus = (function () { | ||
}; | ||
XorShift128Plus.prototype.getState = function () { | ||
return [this.s01, this.s00, this.s11, this.s10]; | ||
}; | ||
return XorShift128Plus; | ||
}()); | ||
export var xorshift128plus = function (seed) { | ||
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 }); |
@@ -13,4 +13,4 @@ import { generateN, skipN, unsafeGenerateN, unsafeSkipN } from './generator/RandomGenerator.js'; | ||
var __type = 'module'; | ||
var __version = '6.0.4'; | ||
var __commitHash = 'bcf9517d53f733a335e678fbba321780c0543b29'; | ||
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, }; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export declare const congruential32: (seed: number) => RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
export declare const congruential32: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export {}; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export default function (seed: number): RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
declare const _default: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export default _default; |
@@ -7,2 +7,3 @@ export interface RandomGenerator { | ||
unsafeJump?(): void; | ||
getState?(): readonly number[]; | ||
} | ||
@@ -9,0 +10,0 @@ export declare function unsafeGenerateN(rng: RandomGenerator, num: number): number[]; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export declare const xoroshiro128plus: (seed: number) => RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
export declare const xoroshiro128plus: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export {}; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export declare const xorshift128plus: (seed: number) => RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
export declare const xorshift128plus: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export {}; |
@@ -36,7 +36,16 @@ "use strict"; | ||
}; | ||
LinearCongruential32.prototype.getState = function () { | ||
return [this.seed]; | ||
}; | ||
return LinearCongruential32; | ||
}()); | ||
var congruential32 = function (seed) { | ||
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); | ||
}; | ||
exports.congruential32 = congruential32; | ||
}, { fromState: fromState }); |
"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; | ||
@@ -54,2 +79,12 @@ var MersenneTwister = (function () { | ||
}; | ||
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; | ||
@@ -70,5 +105,7 @@ MersenneTwister.M = 397; | ||
}()); | ||
function default_1(seed) { | ||
function fromState(state) { | ||
return MersenneTwister.fromState(state); | ||
} | ||
exports["default"] = Object.assign(function (seed) { | ||
return MersenneTwister.from(seed); | ||
} | ||
exports["default"] = default_1; | ||
}, { fromState: fromState }); |
@@ -58,7 +58,16 @@ "use strict"; | ||
}; | ||
XoroShiro128Plus.prototype.getState = function () { | ||
return [this.s01, this.s00, this.s11, this.s10]; | ||
}; | ||
return XoroShiro128Plus; | ||
}()); | ||
var xoroshiro128plus = function (seed) { | ||
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); | ||
}; | ||
exports.xoroshiro128plus = xoroshiro128plus; | ||
}, { fromState: fromState }); |
@@ -58,7 +58,16 @@ "use strict"; | ||
}; | ||
XorShift128Plus.prototype.getState = function () { | ||
return [this.s01, this.s00, this.s11, this.s10]; | ||
}; | ||
return XorShift128Plus; | ||
}()); | ||
var xorshift128plus = function (seed) { | ||
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); | ||
}; | ||
exports.xorshift128plus = xorshift128plus; | ||
}, { fromState: fromState }); |
@@ -31,5 +31,5 @@ "use strict"; | ||
exports.__type = __type; | ||
var __version = '6.0.4'; | ||
var __version = '6.1.0'; | ||
exports.__version = __version; | ||
var __commitHash = 'bcf9517d53f733a335e678fbba321780c0543b29'; | ||
var __commitHash = 'a413dd2b721516be2ef29adffb515c5ae67bfbad'; | ||
exports.__commitHash = __commitHash; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export declare const congruential32: (seed: number) => RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
export declare const congruential32: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export {}; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export default function (seed: number): RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
declare const _default: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export default _default; |
@@ -7,2 +7,3 @@ export interface RandomGenerator { | ||
unsafeJump?(): void; | ||
getState?(): readonly number[]; | ||
} | ||
@@ -9,0 +10,0 @@ export declare function unsafeGenerateN(rng: RandomGenerator, num: number): number[]; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export declare const xoroshiro128plus: (seed: number) => RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
export declare const xoroshiro128plus: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export {}; |
import { RandomGenerator } from './RandomGenerator.js'; | ||
export declare const xorshift128plus: (seed: number) => RandomGenerator; | ||
declare function fromState(state: readonly number[]): RandomGenerator; | ||
export declare const xorshift128plus: ((seed: number) => RandomGenerator) & { | ||
fromState: typeof fromState; | ||
}; | ||
export {}; |
{ | ||
"name": "pure-rand", | ||
"version": "6.0.4", | ||
"version": "6.1.0", | ||
"description": " Pure random number generator written in TypeScript", | ||
@@ -26,3 +26,3 @@ "type": "commonjs", | ||
"sideEffects": false, | ||
"packageManager": "yarn@3.6.3", | ||
"packageManager": "yarn@4.1.1", | ||
"scripts": { | ||
@@ -51,14 +51,14 @@ "format:check": "prettier --list-different .", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.5", | ||
"@types/node": "^18.17.17", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.11.30", | ||
"cross-env": "^7.0.3", | ||
"fast-check": "^3.13.0", | ||
"fast-check": "^3.16.0", | ||
"jest": "^29.7.0", | ||
"prettier": "2.8.8", | ||
"replace-in-file": "^7.0.1", | ||
"prettier": "3.2.5", | ||
"replace-in-file": "^7.1.0", | ||
"source-map-support": "^0.5.21", | ||
"tinybench": "^2.5.1", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
"tinybench": "^2.6.0", | ||
"ts-jest": "^29.1.2", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.2" | ||
}, | ||
@@ -65,0 +65,0 @@ "keywords": [ |
84036
1476