@thi.ng/random 3.3.28 → 3.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-03-27T19:05:49Z
3
+ - **Last updated**: 2023-04-19T09:28:07Z
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.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@3.4.0) (2023-04-19)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add INorm.normMinMax(), update ARandom ([89c6b76](https://github.com/thi-ng/umbrella/commit/89c6b76))
17
+
12
18
  ## [3.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@3.3.0) (2022-05-22)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -93,7 +93,7 @@ For Node.js REPL:
93
93
  const random = await import("@thi.ng/random");
94
94
  ```
95
95
 
96
- Package sizes (brotli'd, pre-treeshake): ESM: 1.83 KB
96
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.85 KB
97
97
 
98
98
  ## Dependencies
99
99
 
package/api.d.ts CHANGED
@@ -1,30 +1,53 @@
1
1
  import type { ICopy } from "@thi.ng/api";
2
2
  export interface INorm {
3
3
  /**
4
- * Returns float in [-scale..scale) interval.
4
+ * Returns float in `[-scale..scale)` interval.
5
5
  *
6
6
  * @remarks
7
7
  * Not to be confused with the {@link normal} distribution function. The
8
8
  * name here refers to "normalized".
9
9
  *
10
+ * Also see: https://github.com/thi-ng/umbrella/wiki/Glossary#interval
11
+ *
10
12
  * @param scale - default 1
11
13
  */
12
14
  norm(scale?: number): number;
15
+ /**
16
+ * Similar to {@link INorm.norm}, but returns values in either the
17
+ * `[min..max)` or in the `(-max...min]` interval (i.e. excluding values in
18
+ * the `(-min..min)` range). Both `min` and `max` MUST be >= 0.
19
+ *
20
+ * @remarks
21
+ * See: https://github.com/thi-ng/umbrella/wiki/Glossary#interval
22
+ *
23
+ * @param min
24
+ * @param max
25
+ */
26
+ normMinMax(min: number, max: number): number;
13
27
  }
14
28
  export interface IRandom extends INorm {
15
29
  /**
16
- * Returns unsigned 32bit int [0..0xffffffff]
30
+ * Returns unsigned 32bit int in [0..0xffffffff] interval.
31
+ *
32
+ * @remarks
33
+ * See: https://github.com/thi-ng/umbrella/wiki/Glossary#interval
17
34
  */
18
35
  int(): number;
19
36
  /**
20
37
  * Returns float in [0..max) interval.
21
38
  *
39
+ * @remarks
40
+ * See: https://github.com/thi-ng/umbrella/wiki/Glossary#interval
41
+ *
22
42
  * @param max - default 1
23
43
  */
24
44
  float(max?: number): number;
25
45
  /**
26
46
  * Returns float in [min..max) interval.
27
47
  *
48
+ * @remarks
49
+ * See: https://github.com/thi-ng/umbrella/wiki/Glossary#interval
50
+ *
28
51
  * @param min -
29
52
  * @param max -
30
53
  */
@@ -32,12 +55,20 @@ export interface IRandom extends INorm {
32
55
  /**
33
56
  * Returns int in [min..max) interval.
34
57
  *
58
+ * @remarks
59
+ * See: https://github.com/thi-ng/umbrella/wiki/Glossary#interval
60
+ *
35
61
  * @param min -
36
62
  * @param max -
37
63
  */
38
64
  minmaxInt(min: number, max: number): number;
39
65
  }
40
66
  export interface ISeedable<T> {
67
+ /**
68
+ * (Re)seeds this PRNG instance with given value(s).
69
+ *
70
+ * @param n
71
+ */
41
72
  seed(n: T): this;
42
73
  }
43
74
  export type ISeedableRandom<T> = IRandom & ISeedable<T> & ICopy<IRandom>;
package/arandom.d.ts CHANGED
@@ -3,6 +3,7 @@ export declare abstract class ARandom implements IRandom {
3
3
  abstract int(): number;
4
4
  float(norm?: number): number;
5
5
  norm(norm?: number): number;
6
+ normMinMax(min: number, max: number): number;
6
7
  minmax(min: number, max: number): number;
7
8
  minmaxInt(min: number, max: number): number;
8
9
  }
package/arandom.js CHANGED
@@ -6,6 +6,10 @@ export class ARandom {
6
6
  norm(norm = 1) {
7
7
  return (this.int() * INV_MAX - 0.5) * 2 * norm;
8
8
  }
9
+ normMinMax(min, max) {
10
+ const x = this.minmax(min, max);
11
+ return this.float() < 0.5 ? x : -x;
12
+ }
9
13
  minmax(min, max) {
10
14
  return this.float() * (max - min) + min;
11
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/random",
3
- "version": "3.3.28",
3
+ "version": "3.4.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,18 +34,18 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.7.5",
38
- "@thi.ng/checks": "^3.3.11",
39
- "@thi.ng/errors": "^2.2.14",
40
- "@thi.ng/hex": "^2.3.8"
37
+ "@thi.ng/api": "^8.8.0",
38
+ "@thi.ng/checks": "^3.3.12",
39
+ "@thi.ng/errors": "^2.2.15",
40
+ "@thi.ng/hex": "^2.3.9"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.34.4",
44
- "@thi.ng/testament": "^0.3.14",
44
+ "@thi.ng/testament": "^0.3.15",
45
45
  "rimraf": "^4.4.1",
46
46
  "tools": "^0.0.1",
47
47
  "typedoc": "^0.23.28",
48
- "typescript": "^5.0.2"
48
+ "typescript": "^5.0.4"
49
49
  },
50
50
  "keywords": [
51
51
  "binary",
@@ -156,5 +156,5 @@
156
156
  "ksuid"
157
157
  ]
158
158
  },
159
- "gitHead": "83b15b34326d480cbca0472b20390d4d3bbb792a\n"
159
+ "gitHead": "3a56bc490f1e68754762a503d06327b5b34ff7eb\n"
160
160
  }