@thi.ng/random 3.8.4 → 4.0.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**: 2024-07-06T12:02:19Z
3
+ - **Last updated**: 2024-07-22T13:15:57Z
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,16 @@ 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.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@4.0.0) (2024-07-22)
13
+
14
+ #### 🛑 Breaking changes
15
+
16
+ - migrate/remove UUID functions ([#486](https://github.com/thi-ng/umbrella/issues/486)) ([2ec753e](https://github.com/thi-ng/umbrella/commit/2ec753e))
17
+ - BREAKING CHANGE: migrate UUID functions to [@thi.ng/uuid](https://github.com/thi-ng/umbrella/tree/main/packages/uuid) pkg
18
+ - remove obsolete files
19
+ - update deps/pkg
20
+ - update readme
21
+
12
22
  ## [3.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@3.8.0) (2024-05-08)
13
23
 
14
24
  #### 🚀 Features
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  <!-- This file is generated - DO NOT EDIT! -->
2
2
  <!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
3
- # ![@thi.ng/random](https://media.thi.ng/umbrella/banners-20230807/thing-random.svg?c79b7908)
3
+ # ![@thi.ng/random](https://media.thi.ng/umbrella/banners-20230807/thing-random.svg?58fd6345)
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@thi.ng/random.svg)](https://www.npmjs.com/package/@thi.ng/random)
6
6
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/random.svg)
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 188 standalone projects, maintained as part
10
+ > This is one of 198 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -62,7 +62,6 @@ Partially ported from C implementations taken from [c.thi.ng](http://c.thi.ng).
62
62
  - [`randomID()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/random-id.ts)
63
63
  - [`weightedRandom()` / `weightedRandomKey()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/weighted-random.ts)
64
64
  - [`uniqueIndices()` / `uniqueValuesFrom()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/unique-indices.ts)
65
- - [`uuidv4Bytes()` / `uuid()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/uuid.ts)
66
65
 
67
66
  ## Status
68
67
 
@@ -104,18 +103,18 @@ For Node.js REPL:
104
103
  const rnd = await import("@thi.ng/random");
105
104
  ```
106
105
 
107
- Package sizes (brotli'd, pre-treeshake): ESM: 2.02 KB
106
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.92 KB
108
107
 
109
108
  ## Dependencies
110
109
 
111
110
  - [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
112
- - [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
113
111
  - [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
114
- - [@thi.ng/hex](https://github.com/thi-ng/umbrella/tree/develop/packages/hex)
112
+
113
+ Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
115
114
 
116
115
  ## Usage examples
117
116
 
118
- Several projects in this repo's
117
+ 18 projects in this repo's
119
118
  [/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
120
119
  directory are using this package:
121
120
 
@@ -137,6 +136,7 @@ directory are using this package:
137
136
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/render-audio.png" width="240"/> | Generative audio synth offline renderer and WAV file export | [Demo](https://demo.thi.ng/umbrella/render-audio/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/render-audio) |
138
137
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-evo.jpg" width="240"/> | Evolutionary shader generation using genetic programming | [Demo](https://demo.thi.ng/umbrella/shader-ast-evo/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-evo) |
139
138
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/stacked-layout.png" width="240"/> | Responsive & reactively computed stacked column layout | [Demo](https://demo.thi.ng/umbrella/stacked-layout/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/stacked-layout) |
139
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/thing-packages-quiz.avif" width="240"/> | thi.ng/rdom & thi.ng/rstream based quiz to guess thi.ng package names | [Demo](https://demo.thi.ng/umbrella/thing-packages-quiz/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/thing-packages-quiz) |
140
140
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-game-of-life.png" width="240"/> | Game of Life implemented as WebGL2 multi-pass shader pipeline | [Demo](https://demo.thi.ng/umbrella/webgl-game-of-life/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-game-of-life) |
141
141
 
142
142
  ## API
package/crypto.d.ts CHANGED
@@ -2,8 +2,8 @@ import type { IBuffered, ICopy } from "@thi.ng/api";
2
2
  import { ARandom } from "./arandom.js";
3
3
  /**
4
4
  * Currently browser only, a `window.crypto` backed {@link IRandom}
5
- * implementation. Random values are buffered to minimize overhead. Buffer size
6
- * is configurable via ctor.
5
+ * implementation. Random values are repeatedly buffered to minimize overhead.
6
+ * Buffer size is configurable via ctor.
7
7
  *
8
8
  * @remarks
9
9
  * Internally uses {@link randomBytes} to source values, which falls back to
package/index.d.ts CHANGED
@@ -14,7 +14,6 @@ export * from "./sfc32.js";
14
14
  export * from "./smush32.js";
15
15
  export * from "./system.js";
16
16
  export * from "./unique-indices.js";
17
- export * from "./uuid.js";
18
17
  export * from "./weighted-probability.js";
19
18
  export * from "./weighted-random.js";
20
19
  export * from "./xorshift128.js";
package/index.js CHANGED
@@ -14,7 +14,6 @@ export * from "./sfc32.js";
14
14
  export * from "./smush32.js";
15
15
  export * from "./system.js";
16
16
  export * from "./unique-indices.js";
17
- export * from "./uuid.js";
18
17
  export * from "./weighted-probability.js";
19
18
  export * from "./weighted-random.js";
20
19
  export * from "./xorshift128.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/random",
3
- "version": "3.8.4",
3
+ "version": "4.0.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,10 +36,8 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.5",
40
- "@thi.ng/checks": "^3.6.7",
41
- "@thi.ng/errors": "^2.5.11",
42
- "@thi.ng/hex": "^2.3.49"
39
+ "@thi.ng/api": "^8.11.7",
40
+ "@thi.ng/errors": "^2.5.13"
43
41
  },
44
42
  "devDependencies": {
45
43
  "@microsoft/api-extractor": "^7.47.0",
@@ -62,7 +60,6 @@
62
60
  "typedarray",
63
61
  "typescript",
64
62
  "weighted",
65
- "uuid",
66
63
  "uniform"
67
64
  ],
68
65
  "publishConfig": {
@@ -131,9 +128,6 @@
131
128
  "./unique-indices": {
132
129
  "default": "./unique-indices.js"
133
130
  },
134
- "./uuid": {
135
- "default": "./uuid.js"
136
- },
137
131
  "./weighted-probability": {
138
132
  "default": "./weighted-probability.js"
139
133
  },
@@ -160,5 +154,5 @@
160
154
  "ksuid"
161
155
  ]
162
156
  },
163
- "gitHead": "ba4f2cd15eeb0cae30efe222524da4fed2a57267\n"
157
+ "gitHead": "324d6b7dbf31558329e9fb6452e29b2f7db9c61a\n"
164
158
  }
package/random-bytes.js CHANGED
@@ -1,4 +1,3 @@
1
- import { hasCrypto } from "@thi.ng/checks/has-crypto";
2
1
  import { SYSTEM } from "./system.js";
3
2
  const randomBytesFrom = (rnd, buf, start = 0, end = buf.length) => {
4
3
  for (let i = start; i < end; i++) {
@@ -6,7 +5,7 @@ const randomBytesFrom = (rnd, buf, start = 0, end = buf.length) => {
6
5
  }
7
6
  return buf;
8
7
  };
9
- const randomBytes = hasCrypto() ? (buf, start = 0, end = buf.length) => (window.crypto.getRandomValues(buf.subarray(start, end)), buf) : (buf, start, end) => randomBytesFrom(SYSTEM, buf, start, end);
8
+ const randomBytes = typeof window !== "undefined" && window["crypto"] !== void 0 ? (buf, start = 0, end = buf.length) => (window.crypto.getRandomValues(buf.subarray(start, end)), buf) : (buf, start, end) => randomBytesFrom(SYSTEM, buf, start, end);
10
9
  export {
11
10
  randomBytes,
12
11
  randomBytesFrom
package/uuid.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { IRandom } from "./api.js";
2
- /**
3
- * Depending on if `rnd` is given, uses {@link randomBytesFrom} or
4
- * {@link randomBytes} to fill given (optional) byte array with a new UUIDv4.
5
- * Creates new Uint8Array if none given.
6
- *
7
- * @param buf -
8
- * @param rnd -
9
- */
10
- export declare const uuidv4Bytes: (buf?: Uint8Array, rnd?: IRandom) => Uint8Array;
11
- /**
12
- * Returns a UUID string, either from given byte array, or if omitted, using a
13
- * new UUID v4 produced by {@link uuidv4Bytes}.
14
- *
15
- * @param id - byte array
16
- * @param i - start index
17
- */
18
- export declare const uuid: (id?: ArrayLike<number>, i?: number) => string;
19
- //# sourceMappingURL=uuid.d.ts.map
package/uuid.js DELETED
@@ -1,15 +0,0 @@
1
- import { uuid as $uuid } from "@thi.ng/hex";
2
- import { randomBytes, randomBytesFrom } from "./random-bytes.js";
3
- const uuidv4Bytes = (buf, rnd) => {
4
- buf = buf || new Uint8Array(16);
5
- buf = rnd ? randomBytesFrom(rnd, buf) : randomBytes(buf);
6
- buf[6] = 64 | buf[6] & 15;
7
- buf[8] = 128 | buf[8] & 63;
8
- return buf;
9
- };
10
- const __buf = new Uint8Array(16);
11
- const uuid = (id, i = 0) => $uuid(id || uuidv4Bytes(__buf), i);
12
- export {
13
- uuid,
14
- uuidv4Bytes
15
- };