@xtia/alea-rc 0.0.11 → 0.0.12

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/README.md CHANGED
@@ -6,11 +6,10 @@ Alea is a utility wrapper for turning random numbers into useful values. Give it
6
6
 
7
7
  * Fully typed
8
8
  * Crypto-safe and seeded algorithms out-of-the-box
9
+ * Expressive: code with intent
9
10
  * No dependencies
10
11
  * ~2.4kb minified core
11
- * Ranged int, array shuffling, dice roll, weighted sampling, recursive template phrase generation, UUID, bytes and many more
12
-
13
- ## Brief:
12
+ * Array shuffling, weighted sampling, recursive template phrase generation, UUID, bytes and many more
14
13
 
15
14
  `npm i @xtia/alea` (pending release; use `@xtia/alea-rc` to preview)
16
15
 
@@ -18,14 +17,13 @@ Alea is a utility wrapper for turning random numbers into useful values. Give it
18
17
  import { alea, cryptoAlea } from "@xtia/alea";
19
18
 
20
19
  // generate values (driven by Math.random())
21
- const damage = alea.roll(2, 6); // 2d6
22
- const duration = alea.between(1000, 1500);
20
+ const damage = alea.between(50, 150);
23
21
  const loot = alea.chance(0.125) ? "epic" : "common";
24
22
  const id = alea.string(5, "abcdef0123456789");
25
23
  const npcName = alea.sample(["Alice", "Bob", "Charlie"]);
26
24
 
27
- // secure source (driven by environment's crypto)
28
- const key = cryptoAlea.string(16);
25
+ // same API, secure source (driven by environment's crypto)
26
+ const id = cryptoAlea.string(16, alphanumeric);
29
27
  ```
30
28
  # Custom sources
31
29
 
@@ -64,5 +62,5 @@ const fast = mulberry32("my-seed");
64
62
  const varied = sfc32(1, 2, 3, 4);
65
63
  const strong = xoshiro128pp(5, 6, 7, 8);
66
64
 
67
- const reproducibleRoll = varied.roll(3, 6);
65
+ const reproducibleId = varied.string(12, hexadecimal);
68
66
  ```
package/entry/other.js CHANGED
@@ -4,5 +4,5 @@ export * from "./common.js";
4
4
  * An Alea instance that uses the runtime environment's `crypto` provider as a source
5
5
  */
6
6
  export const cryptoAlea = new Alea(() => {
7
- throw new Error("cryptoAlea is not available in this environment. Consider using createAleaFromByteSource() with your environment's crypto API.");
7
+ throw new Error("cryptoAlea is not available in this environment. Consider using aleaFromByteSource() with your environment's crypto API.");
8
8
  });
@@ -56,7 +56,7 @@ export declare class Alea {
56
56
  * greeting: ["hello", "hi", "{int} blessings"],
57
57
  * addressee: ["world", "planet", "{adjective} @xtia user"],
58
58
  * adjective: ["beautiful", "wonderful"],
59
- * int: () => alea.int(0, 9).toString(),
59
+ * int: () => Math.floor(alea.between(3, 9)).toString(),
60
60
  * }, "{greeting}, {addressee}!")
61
61
  * ```
62
62
  * @param table
package/internal/alea.js CHANGED
@@ -79,7 +79,7 @@ export class Alea {
79
79
  * greeting: ["hello", "hi", "{int} blessings"],
80
80
  * addressee: ["world", "planet", "{adjective} @xtia user"],
81
81
  * adjective: ["beautiful", "wonderful"],
82
- * int: () => alea.int(0, 9).toString(),
82
+ * int: () => Math.floor(alea.between(3, 9)).toString(),
83
83
  * }, "{greeting}, {addressee}!")
84
84
  * ```
85
85
  * @param table
@@ -4,8 +4,8 @@ import { Alea } from "./alea.js";
4
4
  * as a RNG source
5
5
  * @example
6
6
  * ```ts
7
- * const cryptoAlea = createAleaFromByteSource(crypto.getRandomValues);
8
- * const hwAlea = createAleaFromByteSource(hardwareRng.fillBytes);
7
+ * const cryptoAlea = aleaFromByteSource(crypto.getRandomValues);
8
+ * const hwAlea = aleaFromByteSource(hardwareRng.fillBytes);
9
9
  * ```
10
10
  * @param applyBytes A callback that fills a Uint8Array with random bytes
11
11
  * @returns A byte generator-sourced Alea instance
@@ -25,8 +25,8 @@ export declare function aleaFromSeed(seed: number | string): Alea;
25
25
  * Create an Alea instance using a custom function as an RNG source
26
26
  * @example
27
27
  * ```ts
28
- * const basicAlea = createAleaFromFunc(Math.random);
29
- * const lcgAlea = createAleaFromFunc(customRng.next);
28
+ * const basicAlea = aleaFromFunc(Math.random);
29
+ * const lcgAlea = aleaFromFunc(customRng.next);
30
30
  * ```
31
31
  * @param fn Source RNG; a function that returns a value >= 0 and < 1
32
32
  * @returns Custom function-sourced Alea instance
@@ -5,8 +5,8 @@ import { Alea } from "./alea.js";
5
5
  * as a RNG source
6
6
  * @example
7
7
  * ```ts
8
- * const cryptoAlea = createAleaFromByteSource(crypto.getRandomValues);
9
- * const hwAlea = createAleaFromByteSource(hardwareRng.fillBytes);
8
+ * const cryptoAlea = aleaFromByteSource(crypto.getRandomValues);
9
+ * const hwAlea = aleaFromByteSource(hardwareRng.fillBytes);
10
10
  * ```
11
11
  * @param applyBytes A callback that fills a Uint8Array with random bytes
12
12
  * @returns A byte generator-sourced Alea instance
@@ -36,8 +36,8 @@ export function aleaFromSeed(seed) {
36
36
  * Create an Alea instance using a custom function as an RNG source
37
37
  * @example
38
38
  * ```ts
39
- * const basicAlea = createAleaFromFunc(Math.random);
40
- * const lcgAlea = createAleaFromFunc(customRng.next);
39
+ * const basicAlea = aleaFromFunc(Math.random);
40
+ * const lcgAlea = aleaFromFunc(customRng.next);
41
41
  * ```
42
42
  * @param fn Source RNG; a function that returns a value >= 0 and < 1
43
43
  * @returns Custom function-sourced Alea instance
@@ -45,4 +45,4 @@ export function aleaFromSeed(seed) {
45
45
  export function aleaFromFunc(fn) {
46
46
  return new Alea(fn);
47
47
  }
48
- // const xkcdAlea = createAleaFromFunc(() => 4/6); // decided by die roll
48
+ // const xkcdAlea = aleaFromFunc(() => 4/6); // decided by die roll
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtia/alea-rc",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "RNG utilities",
5
5
  "repository": {
6
6
  "url": "https://github.com/tiadrop/alea",