@thi.ng/random 4.0.4 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/README.md +2 -1
- package/package.json +8 -5
- package/system.d.ts +4 -13
- package/system.js +3 -16
- package/wrapped.d.ts +14 -0
- package/wrapped.js +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-10-05T12:12:32Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [4.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@4.1.0) (2024-10-05)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add WrappedRandom, refactor SYSTEM ([73c863f](https://github.com/thi-ng/umbrella/commit/73c863f))
|
|
17
|
+
- replace `SystemRandom` with `WrappedRandom` class
|
|
18
|
+
- refactor `SYSTEM`
|
|
19
|
+
|
|
12
20
|
# [4.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@4.0.0) (2024-07-22)
|
|
13
21
|
|
|
14
22
|
#### 🛑 Breaking changes
|
package/README.md
CHANGED
|
@@ -39,12 +39,13 @@ Pseudo-random number generators w/ unified API, distributions, weighted choices,
|
|
|
39
39
|
|
|
40
40
|
This package provides the `IRandom` interface and various (mostly seedable)
|
|
41
41
|
pseudo-random number generator implementations, incl. `IRandom` wrappers for
|
|
42
|
-
`Math.random()` and `window.crypto`:
|
|
42
|
+
`Math.random()` (or other external PRNGs) and `window.crypto`:
|
|
43
43
|
|
|
44
44
|
- [Crypto](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/crypto.ts)
|
|
45
45
|
- [SFC32](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/sfc32.ts)
|
|
46
46
|
- [Smush32](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/smush32.ts)
|
|
47
47
|
- [System](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/system.ts)
|
|
48
|
+
- [WrappedRandom](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/wrapped.ts)
|
|
48
49
|
- [Xoshiro128](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/xoshiro128.ts)
|
|
49
50
|
- [XorShift128](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/xorshift128.ts)
|
|
50
51
|
- [XorWow](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/xorwow.ts)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/random",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/errors": "^2.5.
|
|
39
|
+
"@thi.ng/api": "^8.11.11",
|
|
40
|
+
"@thi.ng/errors": "^2.5.17"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@microsoft/api-extractor": "^7.47.9",
|
|
44
|
-
"esbuild": "^0.
|
|
44
|
+
"esbuild": "^0.24.0",
|
|
45
45
|
"typedoc": "^0.26.7",
|
|
46
46
|
"typescript": "^5.6.2"
|
|
47
47
|
},
|
|
@@ -134,6 +134,9 @@
|
|
|
134
134
|
"./weighted-random": {
|
|
135
135
|
"default": "./weighted-random.js"
|
|
136
136
|
},
|
|
137
|
+
"./wrapped": {
|
|
138
|
+
"default": "./wrapped.js"
|
|
139
|
+
},
|
|
137
140
|
"./xorshift128": {
|
|
138
141
|
"default": "./xorshift128.js"
|
|
139
142
|
},
|
|
@@ -154,5 +157,5 @@
|
|
|
154
157
|
"ksuid"
|
|
155
158
|
]
|
|
156
159
|
},
|
|
157
|
-
"gitHead": "
|
|
160
|
+
"gitHead": "11ae480076e61a2263f5730ffb37dfddbf01c7d1\n"
|
|
158
161
|
}
|
package/system.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WrappedRandom } from "./wrapped.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* {@link IRandom} wrapper for `Math.random()`. Used as default PRNG throughout
|
|
4
|
+
* most other thi.ng projects, though usually is configurable.
|
|
5
5
|
*/
|
|
6
|
-
export declare
|
|
7
|
-
int(): number;
|
|
8
|
-
float(norm?: number): number;
|
|
9
|
-
norm(norm?: number): number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Used as default PRNG throughout most other thi.ng projects, though usually is
|
|
13
|
-
* configurable.
|
|
14
|
-
*/
|
|
15
|
-
export declare const SYSTEM: SystemRandom;
|
|
6
|
+
export declare const SYSTEM: WrappedRandom;
|
|
16
7
|
//# sourceMappingURL=system.d.ts.map
|
package/system.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
class SystemRandom extends ARandom {
|
|
4
|
-
int() {
|
|
5
|
-
return random() * 4294967296 >>> 0;
|
|
6
|
-
}
|
|
7
|
-
float(norm = 1) {
|
|
8
|
-
return random() * norm;
|
|
9
|
-
}
|
|
10
|
-
norm(norm = 1) {
|
|
11
|
-
return (random() - 0.5) * 2 * norm;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const SYSTEM = new SystemRandom();
|
|
1
|
+
import { WrappedRandom } from "./wrapped.js";
|
|
2
|
+
const SYSTEM = new WrappedRandom(Math.random);
|
|
15
3
|
export {
|
|
16
|
-
SYSTEM
|
|
17
|
-
SystemRandom
|
|
4
|
+
SYSTEM
|
|
18
5
|
};
|
package/wrapped.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Fn0 } from "@thi.ng/api";
|
|
2
|
+
import { ARandom } from "./arandom.js";
|
|
3
|
+
/**
|
|
4
|
+
* {@link IRandom} implementation for external `Math.random()` compatible PRNG
|
|
5
|
+
* functions. Also see {@link SYSTEM}.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WrappedRandom extends ARandom {
|
|
8
|
+
protected rnd: Fn0<number>;
|
|
9
|
+
constructor(rnd: Fn0<number>);
|
|
10
|
+
float(norm?: number): number;
|
|
11
|
+
norm(norm?: number): number;
|
|
12
|
+
int(): number;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=wrapped.d.ts.map
|
package/wrapped.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ARandom } from "./arandom.js";
|
|
2
|
+
class WrappedRandom extends ARandom {
|
|
3
|
+
constructor(rnd) {
|
|
4
|
+
super();
|
|
5
|
+
this.rnd = rnd;
|
|
6
|
+
}
|
|
7
|
+
float(norm = 1) {
|
|
8
|
+
return this.rnd() * norm;
|
|
9
|
+
}
|
|
10
|
+
norm(norm = 1) {
|
|
11
|
+
return (this.rnd() - 0.5) * 2 * norm;
|
|
12
|
+
}
|
|
13
|
+
int() {
|
|
14
|
+
return this.rnd() * 4294967296 >>> 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
WrappedRandom
|
|
19
|
+
};
|