@thi.ng/random 3.2.1 → 3.2.4
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 +7 -1
- package/README.md +2 -2
- package/api.d.ts +1 -1
- package/arandom.js +1 -1
- package/coin.d.ts +2 -2
- package/coin.js +2 -2
- package/distributions/exponential.d.ts +1 -1
- package/distributions/exponential.js +1 -1
- package/distributions/geometric.d.ts +1 -1
- package/distributions/geometric.js +1 -1
- package/distributions/normal.d.ts +3 -3
- package/distributions/normal.js +3 -3
- package/distributions/uniform.d.ts +3 -3
- package/distributions/uniform.js +3 -3
- package/package.json +10 -10
- package/pick-random.d.ts +4 -4
- package/pick-random.js +4 -4
- package/unique-indices.d.ts +9 -9
- package/unique-indices.js +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2022-03-11T12:13:49Z
|
|
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,12 @@ 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
|
+
### [3.2.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@3.2.2) (2021-11-21)
|
|
13
|
+
|
|
14
|
+
#### 🩹 Bug fixes
|
|
15
|
+
|
|
16
|
+
- off-by-one error in ARandom ([0bf9828](https://github.com/thi-ng/umbrella/commit/0bf9828))
|
|
17
|
+
|
|
12
18
|
## [3.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@3.2.0) (2021-11-17)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ node --experimental-repl-await
|
|
|
89
89
|
> const random = await import("@thi.ng/random");
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
Package sizes (gzipped, pre-treeshake): ESM: 1.
|
|
92
|
+
Package sizes (gzipped, pre-treeshake): ESM: 1.84 KB
|
|
93
93
|
|
|
94
94
|
## Dependencies
|
|
95
95
|
|
|
@@ -160,4 +160,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
160
160
|
|
|
161
161
|
## License
|
|
162
162
|
|
|
163
|
-
© 2015 -
|
|
163
|
+
© 2015 - 2022 Karsten Schmidt // Apache Software License 2.0
|
package/api.d.ts
CHANGED
package/arandom.js
CHANGED
package/coin.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { IRandom } from "./api.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* Also see {@link fairCoin}.
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
9
|
+
* @param rnd -
|
|
10
10
|
*/
|
|
11
11
|
export declare const coin: (rnd?: IRandom) => boolean;
|
|
12
12
|
/**
|
|
@@ -18,7 +18,7 @@ export declare const coin: (rnd?: IRandom) => boolean;
|
|
|
18
18
|
* Reference:
|
|
19
19
|
* https://en.m.wikipedia.org/wiki/Fair_coin#Fair_results_from_a_biased_coin
|
|
20
20
|
*
|
|
21
|
-
* @param rnd
|
|
21
|
+
* @param rnd -
|
|
22
22
|
*/
|
|
23
23
|
export declare const fairCoin: (rnd?: IRandom) => boolean;
|
|
24
24
|
//# sourceMappingURL=coin.d.ts.map
|
package/coin.js
CHANGED
|
@@ -6,7 +6,7 @@ import { SYSTEM } from "./system.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* Also see {@link fairCoin}.
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
9
|
+
* @param rnd -
|
|
10
10
|
*/
|
|
11
11
|
export const coin = (rnd = SYSTEM) => rnd.float() < 0.5;
|
|
12
12
|
/**
|
|
@@ -18,7 +18,7 @@ export const coin = (rnd = SYSTEM) => rnd.float() < 0.5;
|
|
|
18
18
|
* Reference:
|
|
19
19
|
* https://en.m.wikipedia.org/wiki/Fair_coin#Fair_results_from_a_biased_coin
|
|
20
20
|
*
|
|
21
|
-
* @param rnd
|
|
21
|
+
* @param rnd -
|
|
22
22
|
*/
|
|
23
23
|
export const fairCoin = (rnd = SYSTEM) => {
|
|
24
24
|
let a, b;
|
|
@@ -6,7 +6,7 @@ import type { IRandom } from "../api.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* https://en.wikipedia.org/wiki/Exponential_distribution
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
9
|
+
* @param rnd -
|
|
10
10
|
* @param lambda - event interval [0,Inf)
|
|
11
11
|
*/
|
|
12
12
|
export declare const exponential: (rnd?: IRandom, lambda?: number) => () => number;
|
|
@@ -6,7 +6,7 @@ import { SYSTEM } from "../system.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* https://en.wikipedia.org/wiki/Exponential_distribution
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
9
|
+
* @param rnd -
|
|
10
10
|
* @param lambda - event interval [0,Inf)
|
|
11
11
|
*/
|
|
12
12
|
export const exponential = (rnd = SYSTEM, lambda = 10) => lambda === 0 ? () => Infinity : () => -Math.log(1 - rnd.float(1)) / lambda;
|
|
@@ -9,7 +9,7 @@ import type { IRandom } from "../api.js";
|
|
|
9
9
|
*
|
|
10
10
|
* Reference: https://en.wikipedia.org/wiki/Geometric_distribution
|
|
11
11
|
*
|
|
12
|
-
* @param rnd
|
|
12
|
+
* @param rnd -
|
|
13
13
|
* @param p - probability (0,1]
|
|
14
14
|
*/
|
|
15
15
|
export declare const geometric: (rnd?: IRandom, p?: number) => () => number;
|
|
@@ -6,9 +6,9 @@ import type { IRandom } from "../api.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* Also see {@link gaussian} for alternative implementation.
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
10
|
-
* @param bias
|
|
11
|
-
* @param sigma
|
|
9
|
+
* @param rnd -
|
|
10
|
+
* @param bias -
|
|
11
|
+
* @param sigma -
|
|
12
12
|
*/
|
|
13
13
|
export declare const normal: (rnd?: IRandom, bias?: number, sigma?: number) => () => number;
|
|
14
14
|
//# sourceMappingURL=normal.d.ts.map
|
package/distributions/normal.js
CHANGED
|
@@ -6,9 +6,9 @@ import { SYSTEM } from "../system.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* Also see {@link gaussian} for alternative implementation.
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
10
|
-
* @param bias
|
|
11
|
-
* @param sigma
|
|
9
|
+
* @param rnd -
|
|
10
|
+
* @param bias -
|
|
11
|
+
* @param sigma -
|
|
12
12
|
*/
|
|
13
13
|
export const normal = (rnd = SYSTEM, bias = 0, sigma = 1) => {
|
|
14
14
|
let a;
|
|
@@ -6,9 +6,9 @@ import type { IRandom } from "../api.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* This function is syntax sugar for `rnd.minmax()`.
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
10
|
-
* @param min
|
|
11
|
-
* @param max
|
|
9
|
+
* @param rnd -
|
|
10
|
+
* @param min -
|
|
11
|
+
* @param max -
|
|
12
12
|
*/
|
|
13
13
|
export declare const uniform: (rnd?: IRandom, min?: number, max?: number) => () => number;
|
|
14
14
|
//# sourceMappingURL=uniform.d.ts.map
|
package/distributions/uniform.js
CHANGED
|
@@ -6,8 +6,8 @@ import { SYSTEM } from "../system.js";
|
|
|
6
6
|
* @remarks
|
|
7
7
|
* This function is syntax sugar for `rnd.minmax()`.
|
|
8
8
|
*
|
|
9
|
-
* @param rnd
|
|
10
|
-
* @param min
|
|
11
|
-
* @param max
|
|
9
|
+
* @param rnd -
|
|
10
|
+
* @param min -
|
|
11
|
+
* @param max -
|
|
12
12
|
*/
|
|
13
13
|
export const uniform = (rnd = SYSTEM, min = 0, max = 1) => () => rnd.minmax(min, max);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/random",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.4",
|
|
4
4
|
"description": "Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.3.
|
|
38
|
-
"@thi.ng/checks": "^3.1.
|
|
39
|
-
"@thi.ng/errors": "^2.1.
|
|
40
|
-
"@thi.ng/hex": "^2.1.
|
|
37
|
+
"@thi.ng/api": "^8.3.4",
|
|
38
|
+
"@thi.ng/checks": "^3.1.4",
|
|
39
|
+
"@thi.ng/errors": "^2.1.4",
|
|
40
|
+
"@thi.ng/hex": "^2.1.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@microsoft/api-extractor": "^7.
|
|
44
|
-
"@thi.ng/testament": "^0.2.
|
|
43
|
+
"@microsoft/api-extractor": "^7.19.4",
|
|
44
|
+
"@thi.ng/testament": "^0.2.4",
|
|
45
45
|
"rimraf": "^3.0.2",
|
|
46
46
|
"tools": "^0.0.1",
|
|
47
|
-
"typedoc": "^0.22.
|
|
48
|
-
"typescript": "^4.
|
|
47
|
+
"typedoc": "^0.22.13",
|
|
48
|
+
"typescript": "^4.6.2"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"binary",
|
|
@@ -153,5 +153,5 @@
|
|
|
153
153
|
"ksuid"
|
|
154
154
|
]
|
|
155
155
|
},
|
|
156
|
-
"gitHead": "
|
|
156
|
+
"gitHead": "0fc692a3225c068aacafdc4cb6140cf603c67ad8\n"
|
|
157
157
|
}
|
package/pick-random.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* (default: {@link SYSTEM}). The index selection will be constrained to the
|
|
4
4
|
* `[start,end)` interval (default: entire array).
|
|
5
5
|
*
|
|
6
|
-
* @param src
|
|
7
|
-
* @param rnd
|
|
8
|
-
* @param start
|
|
9
|
-
* @param end
|
|
6
|
+
* @param src -
|
|
7
|
+
* @param rnd -
|
|
8
|
+
* @param start -
|
|
9
|
+
* @param end -
|
|
10
10
|
*/
|
|
11
11
|
export declare const pickRandom: <T>(src: ArrayLike<T>, rnd?: import("./system.js").SystemRandom, start?: number, end?: number) => T;
|
|
12
12
|
//# sourceMappingURL=pick-random.d.ts.map
|
package/pick-random.js
CHANGED
|
@@ -4,9 +4,9 @@ import { SYSTEM } from "./system.js";
|
|
|
4
4
|
* (default: {@link SYSTEM}). The index selection will be constrained to the
|
|
5
5
|
* `[start,end)` interval (default: entire array).
|
|
6
6
|
*
|
|
7
|
-
* @param src
|
|
8
|
-
* @param rnd
|
|
9
|
-
* @param start
|
|
10
|
-
* @param end
|
|
7
|
+
* @param src -
|
|
8
|
+
* @param rnd -
|
|
9
|
+
* @param start -
|
|
10
|
+
* @param end -
|
|
11
11
|
*/
|
|
12
12
|
export const pickRandom = (src, rnd = SYSTEM, start = 0, end = src.length) => src[rnd.minmax(start, end) | 0];
|
package/unique-indices.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ import type { IRandom } from "./api.js";
|
|
|
6
6
|
* samples (or creates a new one). Returns the array. Gives up after
|
|
7
7
|
* `maxTrials`.
|
|
8
8
|
*
|
|
9
|
-
* @param k
|
|
10
|
-
* @param fn
|
|
11
|
-
* @param existing
|
|
12
|
-
* @param maxTrials
|
|
9
|
+
* @param k -
|
|
10
|
+
* @param fn -
|
|
11
|
+
* @param existing -
|
|
12
|
+
* @param maxTrials -
|
|
13
13
|
*/
|
|
14
14
|
export declare const uniqueValuesFrom: (k: number, fn: Fn0<number>, existing?: number[], maxTrials?: number) => number[];
|
|
15
15
|
/**
|
|
@@ -22,11 +22,11 @@ export declare const uniqueValuesFrom: (k: number, fn: Fn0<number>, existing?: n
|
|
|
22
22
|
* Candidates are drawn from the provided `rnd` {@link IRandom} (default:
|
|
23
23
|
* {@link SYSTEM}) and only `maxTrials` are attempted before giving up.
|
|
24
24
|
*
|
|
25
|
-
* @param k
|
|
26
|
-
* @param max
|
|
27
|
-
* @param existing
|
|
28
|
-
* @param maxTrials
|
|
29
|
-
* @param rnd
|
|
25
|
+
* @param k -
|
|
26
|
+
* @param max -
|
|
27
|
+
* @param existing -
|
|
28
|
+
* @param maxTrials -
|
|
29
|
+
* @param rnd -
|
|
30
30
|
*/
|
|
31
31
|
export declare const uniqueIndices: (k: number, max: number, existing?: number[] | undefined, maxTrials?: number, rnd?: IRandom) => number[];
|
|
32
32
|
//# sourceMappingURL=unique-indices.d.ts.map
|
package/unique-indices.js
CHANGED
|
@@ -6,10 +6,10 @@ import { SYSTEM } from "./system.js";
|
|
|
6
6
|
* samples (or creates a new one). Returns the array. Gives up after
|
|
7
7
|
* `maxTrials`.
|
|
8
8
|
*
|
|
9
|
-
* @param k
|
|
10
|
-
* @param fn
|
|
11
|
-
* @param existing
|
|
12
|
-
* @param maxTrials
|
|
9
|
+
* @param k -
|
|
10
|
+
* @param fn -
|
|
11
|
+
* @param existing -
|
|
12
|
+
* @param maxTrials -
|
|
13
13
|
*/
|
|
14
14
|
export const uniqueValuesFrom = (k, fn, existing = [], maxTrials = 100) => {
|
|
15
15
|
let n = 0;
|
|
@@ -36,11 +36,11 @@ export const uniqueValuesFrom = (k, fn, existing = [], maxTrials = 100) => {
|
|
|
36
36
|
* Candidates are drawn from the provided `rnd` {@link IRandom} (default:
|
|
37
37
|
* {@link SYSTEM}) and only `maxTrials` are attempted before giving up.
|
|
38
38
|
*
|
|
39
|
-
* @param k
|
|
40
|
-
* @param max
|
|
41
|
-
* @param existing
|
|
42
|
-
* @param maxTrials
|
|
43
|
-
* @param rnd
|
|
39
|
+
* @param k -
|
|
40
|
+
* @param max -
|
|
41
|
+
* @param existing -
|
|
42
|
+
* @param maxTrials -
|
|
43
|
+
* @param rnd -
|
|
44
44
|
*/
|
|
45
45
|
export const uniqueIndices = (k, max, existing, maxTrials = max, rnd = SYSTEM) => {
|
|
46
46
|
assert(k >= 0 && k <= max, `k must be in [0, ${max}] interval`);
|