@thi.ng/random 3.0.0 → 3.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 +35 -0
- package/README.md +4 -3
- package/arandom.d.ts +1 -1
- package/coin.d.ts +1 -1
- package/coin.js +1 -1
- package/crypto.d.ts +1 -1
- package/crypto.js +2 -5
- package/distributions/exponential.d.ts +1 -1
- package/distributions/exponential.js +1 -1
- package/distributions/gaussian.d.ts +1 -1
- package/distributions/gaussian.js +1 -1
- package/distributions/geometric.d.ts +1 -1
- package/distributions/geometric.js +1 -1
- package/distributions/normal.d.ts +1 -1
- package/distributions/normal.js +1 -1
- package/distributions/uniform.d.ts +1 -1
- package/distributions/uniform.js +1 -1
- package/index.d.ts +21 -20
- package/index.js +21 -20
- package/package.json +13 -7
- package/pick-random.d.ts +12 -0
- package/pick-random.js +12 -0
- package/random-bytes.d.ts +1 -1
- package/random-bytes.js +1 -1
- package/random-id.d.ts +1 -1
- package/random-id.js +1 -1
- package/smush32.d.ts +2 -2
- package/smush32.js +2 -3
- package/system.d.ts +1 -1
- package/system.js +1 -1
- package/unique-indices.d.ts +1 -1
- package/unique-indices.js +1 -1
- package/uuid.d.ts +1 -1
- package/uuid.js +1 -1
- package/weighted-random.d.ts +1 -1
- package/weighted-random.js +1 -1
- package/xorshift128.d.ts +2 -2
- package/xorshift128.js +2 -3
- package/xorwow.d.ts +2 -2
- package/xorwow.js +2 -3
- package/xoshiro128.d.ts +2 -2
- package/xoshiro128.js +2 -3
- package/xsadd.d.ts +2 -2
- package/xsadd.js +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/random@3.0.3...@thi.ng/random@3.1.0) (2021-10-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **random:** add pickRandom() ([0899aed](https://github.com/thi-ng/umbrella/commit/0899aed89fd691df4ddc5273995a579414f506d8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [3.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/random@3.0.2...@thi.ng/random@3.0.3) (2021-10-15)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @thi.ng/random
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [3.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/random@3.0.1...@thi.ng/random@3.0.2) (2021-10-15)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @thi.ng/random
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## [3.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/random@3.0.0...@thi.ng/random@3.0.1) (2021-10-13)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package @thi.ng/random
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
# [3.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/random@2.4.8...@thi.ng/random@3.0.0) (2021-10-12)
|
|
7
42
|
|
|
8
43
|
|
package/README.md
CHANGED
|
@@ -80,15 +80,16 @@ ES module import:
|
|
|
80
80
|
|
|
81
81
|
[Skypack documentation](https://docs.skypack.dev/)
|
|
82
82
|
|
|
83
|
-
For
|
|
83
|
+
For Node.js REPL:
|
|
84
84
|
|
|
85
85
|
```text
|
|
86
|
-
|
|
86
|
+
# with flag only for < v16
|
|
87
|
+
node --experimental-repl-await
|
|
87
88
|
|
|
88
89
|
> const random = await import("@thi.ng/random");
|
|
89
90
|
```
|
|
90
91
|
|
|
91
|
-
Package sizes (gzipped, pre-treeshake): ESM: 1.
|
|
92
|
+
Package sizes (gzipped, pre-treeshake): ESM: 1.86 KB
|
|
92
93
|
|
|
93
94
|
## Dependencies
|
|
94
95
|
|
package/arandom.d.ts
CHANGED
package/coin.d.ts
CHANGED
package/coin.js
CHANGED
package/crypto.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IBuffered, ICopy } from "@thi.ng/api";
|
|
2
|
-
import { ARandom } from "./arandom";
|
|
2
|
+
import { ARandom } from "./arandom.js";
|
|
3
3
|
/**
|
|
4
4
|
* Currently browser only, a `window.crypto` backed {@link IRandom}
|
|
5
5
|
* implementation. Random values are buffered to minimize overhead. Buffer size
|
package/crypto.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ARandom } from "./arandom";
|
|
2
|
-
import { randomBytes } from "./random-bytes";
|
|
1
|
+
import { ARandom } from "./arandom.js";
|
|
2
|
+
import { randomBytes } from "./random-bytes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Currently browser only, a `window.crypto` backed {@link IRandom}
|
|
5
5
|
* implementation. Random values are buffered to minimize overhead. Buffer size
|
|
@@ -11,9 +11,6 @@ import { randomBytes } from "./random-bytes";
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
export class Crypto extends ARandom {
|
|
14
|
-
buffer;
|
|
15
|
-
u32;
|
|
16
|
-
i;
|
|
17
14
|
/**
|
|
18
15
|
* @param size - buffer size in bytes (will be rounded to next multiple of 4)
|
|
19
16
|
*/
|
package/distributions/normal.js
CHANGED
package/distributions/uniform.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
export * from "./api";
|
|
2
|
-
export * from "./arandom";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./random-bytes";
|
|
12
|
-
export * from "./random-id";
|
|
13
|
-
export * from "./
|
|
14
|
-
export * from "./
|
|
15
|
-
export * from "./
|
|
16
|
-
export * from "./
|
|
17
|
-
export * from "./
|
|
18
|
-
export * from "./
|
|
19
|
-
export * from "./
|
|
20
|
-
export * from "./
|
|
1
|
+
export * from "./api.js";
|
|
2
|
+
export * from "./arandom.js";
|
|
3
|
+
export * from "./coin.js";
|
|
4
|
+
export * from "./crypto.js";
|
|
5
|
+
export * from "./distributions/exponential.js";
|
|
6
|
+
export * from "./distributions/gaussian.js";
|
|
7
|
+
export * from "./distributions/geometric.js";
|
|
8
|
+
export * from "./distributions/normal.js";
|
|
9
|
+
export * from "./distributions/uniform.js";
|
|
10
|
+
export * from "./pick-random.js";
|
|
11
|
+
export * from "./random-bytes.js";
|
|
12
|
+
export * from "./random-id.js";
|
|
13
|
+
export * from "./smush32.js";
|
|
14
|
+
export * from "./system.js";
|
|
15
|
+
export * from "./unique-indices.js";
|
|
16
|
+
export * from "./uuid.js";
|
|
17
|
+
export * from "./weighted-random.js";
|
|
18
|
+
export * from "./xorshift128.js";
|
|
19
|
+
export * from "./xorwow.js";
|
|
20
|
+
export * from "./xoshiro128.js";
|
|
21
|
+
export * from "./xsadd.js";
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
export * from "./api";
|
|
2
|
-
export * from "./arandom";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./random-bytes";
|
|
12
|
-
export * from "./random-id";
|
|
13
|
-
export * from "./
|
|
14
|
-
export * from "./
|
|
15
|
-
export * from "./
|
|
16
|
-
export * from "./
|
|
17
|
-
export * from "./
|
|
18
|
-
export * from "./
|
|
19
|
-
export * from "./
|
|
20
|
-
export * from "./
|
|
1
|
+
export * from "./api.js";
|
|
2
|
+
export * from "./arandom.js";
|
|
3
|
+
export * from "./coin.js";
|
|
4
|
+
export * from "./crypto.js";
|
|
5
|
+
export * from "./distributions/exponential.js";
|
|
6
|
+
export * from "./distributions/gaussian.js";
|
|
7
|
+
export * from "./distributions/geometric.js";
|
|
8
|
+
export * from "./distributions/normal.js";
|
|
9
|
+
export * from "./distributions/uniform.js";
|
|
10
|
+
export * from "./pick-random.js";
|
|
11
|
+
export * from "./random-bytes.js";
|
|
12
|
+
export * from "./random-id.js";
|
|
13
|
+
export * from "./smush32.js";
|
|
14
|
+
export * from "./system.js";
|
|
15
|
+
export * from "./unique-indices.js";
|
|
16
|
+
export * from "./uuid.js";
|
|
17
|
+
export * from "./weighted-random.js";
|
|
18
|
+
export * from "./xorshift128.js";
|
|
19
|
+
export * from "./xorwow.js";
|
|
20
|
+
export * from "./xoshiro128.js";
|
|
21
|
+
export * from "./xsadd.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/random",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.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",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.0.
|
|
38
|
-
"@thi.ng/checks": "^3.0.
|
|
39
|
-
"@thi.ng/errors": "^2.0.
|
|
40
|
-
"@thi.ng/hex": "^2.0.
|
|
37
|
+
"@thi.ng/api": "^8.0.4",
|
|
38
|
+
"@thi.ng/checks": "^3.0.4",
|
|
39
|
+
"@thi.ng/errors": "^2.0.4",
|
|
40
|
+
"@thi.ng/hex": "^2.0.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@thi.ng/testament": "^0.1.
|
|
43
|
+
"@thi.ng/testament": "^0.1.4"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|
|
46
46
|
"binary",
|
|
@@ -63,6 +63,9 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=12.7"
|
|
68
|
+
},
|
|
66
69
|
"files": [
|
|
67
70
|
"*.js",
|
|
68
71
|
"*.d.ts",
|
|
@@ -102,6 +105,9 @@
|
|
|
102
105
|
"./distributions/uniform": {
|
|
103
106
|
"import": "./distributions/uniform.js"
|
|
104
107
|
},
|
|
108
|
+
"./pick-random": {
|
|
109
|
+
"import": "./pick-random.js"
|
|
110
|
+
},
|
|
105
111
|
"./random-bytes": {
|
|
106
112
|
"import": "./random-bytes.js"
|
|
107
113
|
},
|
|
@@ -142,5 +148,5 @@
|
|
|
142
148
|
"ksuid"
|
|
143
149
|
]
|
|
144
150
|
},
|
|
145
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "9ff00a103f76cc4917ef3f244132e218f2300a05"
|
|
146
152
|
}
|
package/pick-random.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a random element from `src` using given {@link IRandom} instance
|
|
3
|
+
* (default: {@link SYSTEM}). The index selection will be constrained to the
|
|
4
|
+
* `[start,end)` interval (default: entire array).
|
|
5
|
+
*
|
|
6
|
+
* @param src
|
|
7
|
+
* @param rnd
|
|
8
|
+
* @param start
|
|
9
|
+
* @param end
|
|
10
|
+
*/
|
|
11
|
+
export declare const pickRandom: <T>(src: ArrayLike<T>, rnd?: import("./system.js").SystemRandom, start?: number, end?: number) => T;
|
|
12
|
+
//# sourceMappingURL=pick-random.d.ts.map
|
package/pick-random.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SYSTEM } from "./system.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a random element from `src` using given {@link IRandom} instance
|
|
4
|
+
* (default: {@link SYSTEM}). The index selection will be constrained to the
|
|
5
|
+
* `[start,end)` interval (default: entire array).
|
|
6
|
+
*
|
|
7
|
+
* @param src
|
|
8
|
+
* @param rnd
|
|
9
|
+
* @param start
|
|
10
|
+
* @param end
|
|
11
|
+
*/
|
|
12
|
+
export const pickRandom = (src, rnd = SYSTEM, start = 0, end = src.length) => src[rnd.minmax(start, end) | 0];
|
package/random-bytes.d.ts
CHANGED
package/random-bytes.js
CHANGED
package/random-id.d.ts
CHANGED
package/random-id.js
CHANGED
package/smush32.d.ts
CHANGED
package/smush32.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ARandom } from "./arandom";
|
|
2
|
-
import { DEFAULT_SEED_32 } from "./constants";
|
|
1
|
+
import { ARandom } from "./arandom.js";
|
|
2
|
+
import { DEFAULT_SEED_32 } from "./constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* @remarks
|
|
5
5
|
* References:
|
|
@@ -8,7 +8,6 @@ import { DEFAULT_SEED_32 } from "./constants";
|
|
|
8
8
|
* - https://gist.github.com/voidqk/d112165a26b45244a65298933c0349a4
|
|
9
9
|
*/
|
|
10
10
|
export class Smush32 extends ARandom {
|
|
11
|
-
buffer;
|
|
12
11
|
constructor(seed = DEFAULT_SEED_32) {
|
|
13
12
|
super();
|
|
14
13
|
this.buffer = new Uint32Array([seed, 0]);
|
package/system.d.ts
CHANGED
package/system.js
CHANGED
package/unique-indices.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Fn0 } from "@thi.ng/api";
|
|
2
|
-
import type { IRandom } from "./api";
|
|
2
|
+
import type { IRandom } from "./api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Attempts to draw `k` unique values from given zero-arg function `fn`
|
|
5
5
|
* (presumably a PRNG of sorts) and adds them to `existing` array of unique
|
package/unique-indices.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from "@thi.ng/errors/assert";
|
|
2
|
-
import { SYSTEM } from "./system";
|
|
2
|
+
import { SYSTEM } from "./system.js";
|
|
3
3
|
/**
|
|
4
4
|
* Attempts to draw `k` unique values from given zero-arg function `fn`
|
|
5
5
|
* (presumably a PRNG of sorts) and adds them to `existing` array of unique
|
package/uuid.d.ts
CHANGED
package/uuid.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { uuid as $uuid } from "@thi.ng/hex";
|
|
2
|
-
import { randomBytes, randomBytesFrom } from "./random-bytes";
|
|
2
|
+
import { randomBytes, randomBytesFrom } from "./random-bytes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Depending on if `rnd` is given, uses {@link randomBytesFrom} or
|
|
5
5
|
* {@link randomBytes} to fill given (optional) byte array with a new UUIDv4.
|
package/weighted-random.d.ts
CHANGED
package/weighted-random.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from "@thi.ng/errors/assert";
|
|
2
|
-
import { SYSTEM } from "./system";
|
|
2
|
+
import { SYSTEM } from "./system.js";
|
|
3
3
|
/**
|
|
4
4
|
* Returns a no-arg function which produces a random choice of given weighted
|
|
5
5
|
* `choices` and using given {@link IRandom} instance (default {@link SYSTEM}.
|
package/xorshift128.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IBuffered, ICopy } from "@thi.ng/api";
|
|
2
|
-
import type { ISeedable } from "./api";
|
|
3
|
-
import { ARandom } from "./arandom";
|
|
2
|
+
import type { ISeedable } from "./api.js";
|
|
3
|
+
import { ARandom } from "./arandom.js";
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
6
6
|
* Reference: https://en.wikipedia.org/wiki/Xorshift
|
package/xorshift128.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ARandom } from "./arandom";
|
|
2
|
-
import { DEFAULT_SEED_128 } from "./constants";
|
|
1
|
+
import { ARandom } from "./arandom.js";
|
|
2
|
+
import { DEFAULT_SEED_128 } from "./constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* @remarks
|
|
5
5
|
* Reference: https://en.wikipedia.org/wiki/Xorshift
|
|
6
6
|
*/
|
|
7
7
|
export class XorShift128 extends ARandom {
|
|
8
|
-
buffer;
|
|
9
8
|
constructor(seed = DEFAULT_SEED_128) {
|
|
10
9
|
super();
|
|
11
10
|
this.buffer = new Uint32Array(4);
|
package/xorwow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IBuffered, ICopy } from "@thi.ng/api";
|
|
2
|
-
import type { ISeedable } from "./api";
|
|
3
|
-
import { ARandom } from "./arandom";
|
|
2
|
+
import type { ISeedable } from "./api.js";
|
|
3
|
+
import { ARandom } from "./arandom.js";
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
6
6
|
* Reference: https://en.wikipedia.org/wiki/Xorshift#xorwow
|
package/xorwow.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ARandom } from "./arandom";
|
|
2
|
-
import { DEFAULT_SEED_160 } from "./constants";
|
|
1
|
+
import { ARandom } from "./arandom.js";
|
|
2
|
+
import { DEFAULT_SEED_160 } from "./constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* @remarks
|
|
5
5
|
* Reference: https://en.wikipedia.org/wiki/Xorshift#xorwow
|
|
6
6
|
*/
|
|
7
7
|
export class XorWow extends ARandom {
|
|
8
|
-
buffer;
|
|
9
8
|
constructor(seed = DEFAULT_SEED_160) {
|
|
10
9
|
super();
|
|
11
10
|
this.buffer = new Uint32Array(5);
|
package/xoshiro128.d.ts
CHANGED
package/xoshiro128.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ARandom } from "./arandom";
|
|
2
|
-
import { DEFAULT_SEED_128 } from "./constants";
|
|
1
|
+
import { ARandom } from "./arandom.js";
|
|
2
|
+
import { DEFAULT_SEED_128 } from "./constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* @remarks
|
|
5
5
|
* References:
|
|
@@ -7,7 +7,6 @@ import { DEFAULT_SEED_128 } from "./constants";
|
|
|
7
7
|
* - http://prng.di.unimi.it/xoshiro128plusplus.c
|
|
8
8
|
*/
|
|
9
9
|
export class Xoshiro128 extends ARandom {
|
|
10
|
-
buffer;
|
|
11
10
|
constructor(seed = DEFAULT_SEED_128) {
|
|
12
11
|
super();
|
|
13
12
|
this.buffer = new Uint32Array(4);
|
package/xsadd.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IBuffered, ICopy } from "@thi.ng/api";
|
|
2
|
-
import type { ISeedable } from "./api";
|
|
3
|
-
import { ARandom } from "./arandom";
|
|
2
|
+
import type { ISeedable } from "./api.js";
|
|
3
|
+
import { ARandom } from "./arandom.js";
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
6
6
|
* Reference: https://github.com/MersenneTwister-Lab/XSadd/blob/develop/xsadd.h
|
package/xsadd.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ARandom } from "./arandom";
|
|
2
|
-
import { DEFAULT_SEED_32 } from "./constants";
|
|
1
|
+
import { ARandom } from "./arandom.js";
|
|
2
|
+
import { DEFAULT_SEED_32 } from "./constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* @remarks
|
|
5
5
|
* Reference: https://github.com/MersenneTwister-Lab/XSadd/blob/develop/xsadd.h
|
|
6
6
|
*/
|
|
7
7
|
export class XsAdd extends ARandom {
|
|
8
|
-
buffer;
|
|
9
8
|
constructor(seed = DEFAULT_SEED_32) {
|
|
10
9
|
super();
|
|
11
10
|
this.buffer = new Uint32Array(4);
|