toosoon-prng 1.3.0 → 1.5.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/README.md CHANGED
@@ -163,7 +163,7 @@ Pick a pseudo-random property value from a given object.
163
163
  - `object`: Object to pick the property from.
164
164
 
165
165
  ```ts
166
- prng.randomObjectProperty<T>(seed: string, object: object): T | undefined;
166
+ prng.randomObjectProperty<T>(seed: string, object: Record<string, T>): T | undefined;
167
167
  ```
168
168
 
169
169
  ##### randomIndex(seed, weights)
@@ -230,7 +230,7 @@ class ItemController<T>(seed: string, items: T[]);
230
230
  Pick a pseudo-random property value from a given object.
231
231
 
232
232
  ```ts
233
- class ObjectPropertyController<T>(seed: string, object: object);
233
+ class ObjectPropertyController<T>(seed: string, object: Record<string, T>);
234
234
  ```
235
235
 
236
236
  ### WeightsController
@@ -311,19 +311,18 @@ class WeightsGroupController<T>(seed: string, items: Array<{ weight: number; val
311
311
 
312
312
  ## Algorithms
313
313
 
314
- By default, the library is using `SplitMix32` algorithm for generating the pseudo-random values but it is possible to change the algorithm used by one of the following:
314
+ By default, the library is using _SplitMix32_ algorithm for generating the pseudo-random values but it is possible to change the algorithm used by one of the following:
315
315
 
316
- - `jsf32`: Jenkins' Small Fast, Generator with a 32-bit state.
317
- - `mulberry32`: Mulberry32, Generator with a 32-bit state.
318
- - `sfc32`: Simple Fast Counter, Generator with a 128-bit state.
319
- - `splitmix32`: SplitMix32, Generator with a 32-bit state.
320
- - `xoshiro128ss`: xoshiro128\*\*, Generator with a 128-bit state.
321
-
322
- **Credits**: [Seeding random number generator in Javascript](https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript)
316
+ - `jsf32`: _Jenkins' Small Fast_, Generator with a 32-bit state.
317
+ - `mulberry32`: _Mulberry32_, Generator with a 32-bit state.
318
+ - `sfc32`: _Simple Fast Counter_, Generator with a 128-bit state.
319
+ - `splitmix32`: _SplitMix32_, Generator with a 32-bit state.
320
+ - `xoshiro128ss`: _xoshiro128\*\*_, Generator with a 128-bit state.
323
321
 
324
322
  ```ts
325
323
  import prng, { Algorithm } from 'toosoon-prng';
326
324
 
325
+ // Set 'Simple Fast Counter' as PRNG instance algorithm
327
326
  prng.setAlgorithm(Algorithm.sfc32);
328
327
  ```
329
328
 
@@ -82,12 +82,8 @@ export declare class ItemController<T = unknown> extends BasePRNGController<T> {
82
82
  }
83
83
  export declare class ObjectPropertyController<T = unknown> extends BasePRNGController<T> {
84
84
  value: T;
85
- object: {
86
- [key: string]: T;
87
- };
88
- constructor(seed: string, object: {
89
- [key: string]: T;
90
- });
85
+ object: Record<string, T>;
86
+ constructor(seed: string, object: Record<string, T>);
91
87
  addGUI(gui: Gui): GuiController;
92
88
  getValue(): T;
93
89
  }
@@ -140,13 +136,9 @@ export declare class ItemGroupController<T = unknown> extends BasePRNGGroupContr
140
136
  createController(index: number): ItemController<T>;
141
137
  }
142
138
  export declare class ObjectPropertyGroupController<T = unknown> extends BasePRNGGroupController<T> {
143
- object: {
144
- [key: string]: T;
145
- };
139
+ object: Record<string, T>;
146
140
  controllers: ObjectPropertyController<T>[];
147
- constructor(seed: string, object: {
148
- [key: string]: T;
149
- });
141
+ constructor(seed: string, object: Record<string, T>);
150
142
  createController(index: number): ObjectPropertyController<T>;
151
143
  }
152
144
  export declare class WeightsGroupController<T = unknown> extends BasePRNGGroupController<T> {
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { BooleanController, SignController, IntController, FloatController, HexColorController, ItemController, ObjectPropertyController, WeightsController, BooleanGroupController, SignGroupController, IntGroupController, FloatGroupController, HexColorGroupController, ItemGroupController, ObjectPropertyGroupController, WeightsGroupController } from './controllers';
2
- export { default, Algorithm } from './prng';
2
+ export { default } from './prng';
3
3
  export type * from './types';
package/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export { BooleanController, SignController, IntController, FloatController, HexColorController, ItemController, ObjectPropertyController, WeightsController, BooleanGroupController, SignGroupController, IntGroupController, FloatGroupController, HexColorGroupController, ItemGroupController, ObjectPropertyGroupController, WeightsGroupController } from './controllers';
2
- export { default, Algorithm } from './prng';
2
+ export { default } from './prng';
package/lib/prng.d.ts CHANGED
@@ -1,19 +1,13 @@
1
1
  import { PRNGController } from './controllers';
2
- export declare enum Algorithm {
3
- jsf32 = "jsf32",
4
- mulberry32 = "mulberry32",
5
- sfc32 = "sfc32",
6
- splitmix32 = "splitmix32",// Default
7
- xoshiro128ss = "xoshiro128**"
8
- }
2
+ import { Algorithm } from './types';
9
3
  /**
10
- * PRNG class
4
+ * Utility class for generating pseudo-random values
11
5
  *
12
6
  * @class PRNG
13
7
  */
14
8
  declare class PRNG {
15
9
  seed: string;
16
- algorithm: Algorithm;
10
+ algorithm: (...args: number[]) => number;
17
11
  controllers: PRNGController[];
18
12
  /**
19
13
  * Add a controller to this PRNG
@@ -104,9 +98,7 @@ declare class PRNG {
104
98
  * @param {object} object Object to pick the property from
105
99
  * @returns {T|undefined} Random item picked
106
100
  */
107
- randomObjectProperty<T = unknown>(seed: string, object: {
108
- [key: string]: T;
109
- }): T | undefined;
101
+ randomObjectProperty<T = unknown>(seed: string, object: Record<string, T>): T | undefined;
110
102
  /**
111
103
  * Select a pseudo-random index from an array of weighted items
112
104
  *
@@ -115,6 +107,13 @@ declare class PRNG {
115
107
  * @returns {number} Random index based on weights
116
108
  */
117
109
  randomIndex(seed: string, weights: number[]): number;
110
+ /**
111
+ * Get the PRNG algorithm function by its name
112
+ *
113
+ * @param {Algorithm} algorithm Algorithm name
114
+ * @returns {Function} PRNG algorithm function
115
+ */
116
+ private getAlgorithm;
118
117
  }
119
118
  declare const prng: PRNG;
120
119
  export default prng;
package/lib/prng.js CHANGED
@@ -1,21 +1,14 @@
1
- import { cyrb128, jsf32, mulberry32, sfc32, splitmix32, xoshiro128ss } from './utils';
2
- export var Algorithm;
3
- (function (Algorithm) {
4
- Algorithm["jsf32"] = "jsf32";
5
- Algorithm["mulberry32"] = "mulberry32";
6
- Algorithm["sfc32"] = "sfc32";
7
- Algorithm["splitmix32"] = "splitmix32";
8
- Algorithm["xoshiro128ss"] = "xoshiro128**";
9
- })(Algorithm || (Algorithm = {}));
1
+ import { jsf32, mulberry32, sfc32, splitmix32, xoshiro128ss, random } from 'toosoon-utils/prng';
2
+ import { Algorithm } from './types';
10
3
  /**
11
- * PRNG class
4
+ * Utility class for generating pseudo-random values
12
5
  *
13
6
  * @class PRNG
14
7
  */
15
8
  var PRNG = /** @class */ (function () {
16
9
  function PRNG() {
17
10
  this.seed = '';
18
- this.algorithm = Algorithm.splitmix32;
11
+ this.algorithm = splitmix32;
19
12
  this.controllers = [];
20
13
  }
21
14
  /**
@@ -52,7 +45,7 @@ var PRNG = /** @class */ (function () {
52
45
  * @param {Algorithm} algorithm Algorithm name
53
46
  */
54
47
  PRNG.prototype.setAlgorithm = function (algorithm) {
55
- this.algorithm = algorithm;
48
+ this.algorithm = this.getAlgorithm(algorithm);
56
49
  this.controllers.forEach(function (controller) { return controller.getValue(); });
57
50
  };
58
51
  /**
@@ -63,19 +56,7 @@ var PRNG = /** @class */ (function () {
63
56
  * @returns {number}
64
57
  */
65
58
  PRNG.prototype.random = function (seed) {
66
- var hashes = cyrb128(this.seed + seed);
67
- switch (this.algorithm) {
68
- case Algorithm.splitmix32:
69
- return splitmix32(hashes[0]);
70
- case Algorithm.jsf32:
71
- return jsf32(hashes[0], hashes[1], hashes[2], hashes[3]);
72
- case Algorithm.mulberry32:
73
- return mulberry32(hashes[0]);
74
- case Algorithm.sfc32:
75
- return sfc32(hashes[0], hashes[1], hashes[2], hashes[3]);
76
- case Algorithm.xoshiro128ss:
77
- return xoshiro128ss(hashes[0], hashes[1], hashes[2], hashes[3]);
78
- }
59
+ return random({ seed: this.seed + seed, algorithm: this.algorithm });
79
60
  };
80
61
  /**
81
62
  * Generate a pseudo-random boolean (true or false)
@@ -172,19 +153,39 @@ var PRNG = /** @class */ (function () {
172
153
  return -1;
173
154
  var totalWeight = 0;
174
155
  for (var _i = 0, weights_1 = weights; _i < weights_1.length; _i++) {
175
- var weight = weights_1[_i];
176
- totalWeight += weight;
156
+ var weight_1 = weights_1[_i];
157
+ totalWeight += weight_1;
177
158
  }
178
159
  if (totalWeight <= 0)
179
160
  console.warn('PRNG.randomIndex()', 'Weights must sum to > 0', totalWeight);
180
- var random = this.random(seed) * totalWeight;
161
+ var weight = this.random(seed) * totalWeight;
181
162
  for (var i = 0; i < weights.length; i++) {
182
- if (random < weights[i])
163
+ if (weight < weights[i])
183
164
  return i;
184
- random -= weights[i];
165
+ weight -= weights[i];
185
166
  }
186
167
  return 0;
187
168
  };
169
+ /**
170
+ * Get the PRNG algorithm function by its name
171
+ *
172
+ * @param {Algorithm} algorithm Algorithm name
173
+ * @returns {Function} PRNG algorithm function
174
+ */
175
+ PRNG.prototype.getAlgorithm = function (algorithm) {
176
+ switch (algorithm) {
177
+ case Algorithm.splitmix32:
178
+ return splitmix32;
179
+ case Algorithm.jsf32:
180
+ return jsf32;
181
+ case Algorithm.mulberry32:
182
+ return mulberry32;
183
+ case Algorithm.sfc32:
184
+ return sfc32;
185
+ case Algorithm.xoshiro128ss:
186
+ return xoshiro128ss;
187
+ }
188
+ };
188
189
  return PRNG;
189
190
  }());
190
191
  var prng = new PRNG();
@@ -1 +1 @@
1
- {"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/typescript/lib/lib.es2023.d.ts","../node_modules/typescript/lib/lib.esnext.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../node_modules/typescript/lib/lib.es2023.array.d.ts","../node_modules/typescript/lib/lib.es2023.collection.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../node_modules/typescript/lib/lib.esnext.disposable.d.ts","../node_modules/typescript/lib/lib.esnext.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../node_modules/toosoon-gui/lib/wrapper.d.ts","../node_modules/toosoon-gui/lib/types.d.ts","../node_modules/toosoon-gui/lib/controllers/controller.d.ts","../node_modules/toosoon-gui/lib/controllers/angle-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/color-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/coords-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/file-controller.d.ts","../node_modules/toosoon-gui/lib/gui.d.ts","../node_modules/toosoon-gui/lib/controllers/boolean-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/function-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/number-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/option-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/string-controller.d.ts","../node_modules/toosoon-gui/lib/index.d.ts","../src/utils.ts","../src/prng.ts","../src/controllers.ts","../src/types.ts","../src/index.ts"],"fileInfos":[{"version":"f33e5332b24c3773e930e212cbb8b6867c8ba3ec4492064ea78e55a524d57450","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","26f2f787e82c4222710f3b676b4d83eb5ad0a72fa7b746f03449e7a026ce5073","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b","bed7b7ba0eb5a160b69af72814b4dde371968e40b6c5e73d3a9f7bee407d158c",{"version":"21e41a76098aa7a191028256e52a726baafd45a925ea5cf0222eb430c96c1d83","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"e0275cd0e42990dc3a16f0b7c8bca3efe87f1c8ad404f80c6db1c7c0b828c59f","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"acae90d417bee324b1372813b5a00829d31c7eb670d299cd7f8f9a648ac05688","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"62a4966981264d1f04c44eb0f4b5bdc3d81c1a54725608861e44755aa24ad6a5","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"86a34c7a13de9cabc43161348f663624b56871ed80986e41d214932ddd8d6719","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"4350e5922fecd4bedda2964d69c213a1436349d0b8d260dd902795f5b94dc74b","affectsGlobalScope":true},{"version":"d4b1d2c51d058fc21ec2629fff7a76249dec2e36e12960ea056e3ef89174080f","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"7f3b56b751819dfc3d25393d8232f400b8cbef152423e71d1e4e5db81cf2e2db","f7e25ae88d386440b751e25f12ec98bdd80822c54e58ed3cb80cc306ae9510e6","32c3a14e4806136096ba2da0c5101889803156a384c25c81d67e872e3be0d3ba","6339a44514a06c5e8f726cf27fc7fb2bf0e2ce5fe0de5545e4d412ba54c209f9","52800b74e97d62cd27f91a19ace28ca7ed32084fc5de80b015c8b62aabb4de99","2eba4de3285ccf1518aa5d87c683e4c4da38a837f69e112710fb107c58e86b9f","7b1267119c9c7c148ee973f8affd943c49f7ec2f5573f83cee25139492b533cd","3c73521cd265c18ed3aca9460bf298e5ed4a147aa3340f30ad7f1d9be05f726b","027d78906c03890d8473731baca3acad76095aa2e68af1c6fcd32ded61d9a430","5eb3db8ef1b8f4eb5b16facea0a1cc3d9c22d6513de77a29c6630233c7ccf888","448bf4331abf7995b2ab5c4a449800e35fc3dbcfb522ed752d84564fd7d17374","3147a65dfdc1827b3a1b3899c5b316e8cc10eeb66f5c26c758bb24b2c962983a","845075e15760edf65e31220cbfc67b0bd436be0cd169181aa524dcf8987ff09e","74427eecc65d24613d8483cb6191d32cb91aa79c2b13084ed2062457e3aa0376",{"version":"26e0b25ad701a5e58597ed82fa62f614efdb387d64597dfbaedf12898786dbd8","signature":"53ec1445b996aa4171b310f7fae307365d18c4a2d140002f499fa3ae3a354122"},{"version":"0f79b0456e9e64ee7d7c17218de9ff8285d2a91fed26103f62fd217cdfcbc74f","signature":"c0c499dc868ff11346ebba826f105635343f7fbdd2005cfe31158b12e725e502"},{"version":"afed0880319d48732105dcd665a9f4dcfa1a46b5ed644a5db3aa7b7f5ec09d68","signature":"273b0b65a6f4847bdc73d02fcf48febd9eb46892c988971b8fe7c4e7a8bbe4db"},"2236ce3736f4dc650fa83c8bcbcfdc0f0107130ffea14f23dbf80a17c508dab4",{"version":"2bbbc5d46cdb4ad6abbba0d268f354b686d54669b4fc7e407dd9723e9c09d213","signature":"5e43ce4afb9e62ad6d6acdba99da315b974b2c118328d1fb828f367ac10febdf"}],"root":[[79,83]],"options":{"allowJs":true,"allowSyntheticDefaultImports":true,"declaration":true,"esModuleInterop":true,"experimentalDecorators":true,"module":99,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","skipLibCheck":true,"strict":true,"target":1},"fileIdsList":[[67,72],[66,72],[66,67,68,69,70,71],[65,66,67,69,71,72,73,74,75,76,77],[65,67,72],[66,67,72],[78,80],[80,81,82],[79,81],[81],[78]],"referencedMap":[[68,1],[73,1],[69,1],[67,2],[70,1],[71,1],[74,1],[75,1],[76,1],[77,1],[72,3],[78,4],[66,5],[65,6],[81,7],[83,8],[80,9],[82,10]],"exportedModulesMap":[[68,1],[73,1],[69,1],[67,2],[70,1],[71,1],[74,1],[75,1],[76,1],[77,1],[72,3],[78,4],[66,5],[65,6],[81,11],[83,8],[80,10],[82,10]],"semanticDiagnosticsPerFile":[68,73,69,67,70,71,74,75,76,77,72,78,66,65,63,64,12,14,13,2,15,16,17,18,19,20,21,22,3,4,23,27,24,25,26,28,29,30,5,31,32,33,34,6,38,35,36,37,39,7,40,45,46,41,42,43,44,8,50,47,48,49,51,9,52,53,54,57,55,56,58,59,10,1,11,62,61,60,81,83,80,82,79]},"version":"5.3.3"}
1
+ {"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/typescript/lib/lib.es2023.d.ts","../node_modules/typescript/lib/lib.esnext.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../node_modules/typescript/lib/lib.es2023.array.d.ts","../node_modules/typescript/lib/lib.es2023.collection.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../node_modules/typescript/lib/lib.esnext.disposable.d.ts","../node_modules/typescript/lib/lib.esnext.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../node_modules/toosoon-gui/lib/wrapper.d.ts","../node_modules/toosoon-gui/lib/types.d.ts","../node_modules/toosoon-gui/lib/controllers/controller.d.ts","../node_modules/toosoon-gui/lib/controllers/angle-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/color-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/coords-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/file-controller.d.ts","../node_modules/toosoon-gui/lib/gui.d.ts","../node_modules/toosoon-gui/lib/controllers/boolean-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/function-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/number-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/option-controller.d.ts","../node_modules/toosoon-gui/lib/controllers/string-controller.d.ts","../node_modules/toosoon-gui/lib/index.d.ts","../node_modules/toosoon-utils/lib/prng.d.ts","../src/types.ts","../src/prng.ts","../src/controllers.ts","../src/index.ts"],"fileInfos":[{"version":"f33e5332b24c3773e930e212cbb8b6867c8ba3ec4492064ea78e55a524d57450","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","26f2f787e82c4222710f3b676b4d83eb5ad0a72fa7b746f03449e7a026ce5073","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b","bed7b7ba0eb5a160b69af72814b4dde371968e40b6c5e73d3a9f7bee407d158c",{"version":"21e41a76098aa7a191028256e52a726baafd45a925ea5cf0222eb430c96c1d83","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"e0275cd0e42990dc3a16f0b7c8bca3efe87f1c8ad404f80c6db1c7c0b828c59f","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"acae90d417bee324b1372813b5a00829d31c7eb670d299cd7f8f9a648ac05688","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"62a4966981264d1f04c44eb0f4b5bdc3d81c1a54725608861e44755aa24ad6a5","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"86a34c7a13de9cabc43161348f663624b56871ed80986e41d214932ddd8d6719","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"4350e5922fecd4bedda2964d69c213a1436349d0b8d260dd902795f5b94dc74b","affectsGlobalScope":true},{"version":"d4b1d2c51d058fc21ec2629fff7a76249dec2e36e12960ea056e3ef89174080f","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"7f3b56b751819dfc3d25393d8232f400b8cbef152423e71d1e4e5db81cf2e2db","f7e25ae88d386440b751e25f12ec98bdd80822c54e58ed3cb80cc306ae9510e6","32c3a14e4806136096ba2da0c5101889803156a384c25c81d67e872e3be0d3ba","6339a44514a06c5e8f726cf27fc7fb2bf0e2ce5fe0de5545e4d412ba54c209f9","52800b74e97d62cd27f91a19ace28ca7ed32084fc5de80b015c8b62aabb4de99","2eba4de3285ccf1518aa5d87c683e4c4da38a837f69e112710fb107c58e86b9f","7b1267119c9c7c148ee973f8affd943c49f7ec2f5573f83cee25139492b533cd","3c73521cd265c18ed3aca9460bf298e5ed4a147aa3340f30ad7f1d9be05f726b","027d78906c03890d8473731baca3acad76095aa2e68af1c6fcd32ded61d9a430","5eb3db8ef1b8f4eb5b16facea0a1cc3d9c22d6513de77a29c6630233c7ccf888","448bf4331abf7995b2ab5c4a449800e35fc3dbcfb522ed752d84564fd7d17374","3147a65dfdc1827b3a1b3899c5b316e8cc10eeb66f5c26c758bb24b2c962983a","845075e15760edf65e31220cbfc67b0bd436be0cd169181aa524dcf8987ff09e","74427eecc65d24613d8483cb6191d32cb91aa79c2b13084ed2062457e3aa0376","bfbf0986270057216327e240d192582c2e1ad64f995251a8e99ef655ae3174f9",{"version":"ee2f644177ac7b3a3103ce205a9ef175f78b8eca8e3aff22e5d566cadfeabba8","signature":"cbfcbe7513193695f971d0f8f16b74a15db97c0078006d0414ea4831c0847115"},{"version":"fdfa07295e9e5e659b416ae8dea7aa759d7ac9ba87097a29cda1aef00cb03e25","signature":"9f91ac498d57a6d0566505dce8ae83eef584b9622cda8418e39b23e76dc4ca68"},{"version":"6aa99d22275a03a2ddddbc13d95f5e9f61cfd3a67463ce3afbf8fd7cff5010a5","signature":"865ca0437ddfa0f4029b468c4fa89c140d9f5c0b06e86877c4bfdad7f528db1e"},{"version":"a0ffa57525eea3df5ac85856ed662c68ceabdc91617a0041d31a24199a92fb44","signature":"cda7ab2d0e9fdf59864625e22e113190ee4b2222ac6bad6dd3c194a883945085"}],"root":[[80,83]],"options":{"allowJs":true,"allowSyntheticDefaultImports":true,"declaration":true,"esModuleInterop":true,"experimentalDecorators":true,"module":99,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","skipLibCheck":true,"strict":true,"target":1},"fileIdsList":[[67,72],[66,72],[66,67,68,69,70,71],[65,66,67,69,71,72,73,74,75,76,77],[65,67,72],[66,67,72],[78,81],[80,81,82],[79,80,82],[82],[78],[80,82]],"referencedMap":[[68,1],[73,1],[69,1],[67,2],[70,1],[71,1],[74,1],[75,1],[76,1],[77,1],[72,3],[78,4],[66,5],[65,6],[82,7],[83,8],[81,9],[80,10]],"exportedModulesMap":[[68,1],[73,1],[69,1],[67,2],[70,1],[71,1],[74,1],[75,1],[76,1],[77,1],[72,3],[78,4],[66,5],[65,6],[82,11],[83,8],[81,12],[80,10]],"semanticDiagnosticsPerFile":[68,73,69,67,70,71,74,75,76,77,72,78,66,65,79,63,64,12,14,13,2,15,16,17,18,19,20,21,22,3,4,23,27,24,25,26,28,29,30,5,31,32,33,34,6,38,35,36,37,39,7,40,45,46,41,42,43,44,8,50,47,48,49,51,9,52,53,54,57,55,56,58,59,10,1,11,62,61,60,82,83,81,80]},"version":"5.3.3"}
package/lib/types.d.ts CHANGED
@@ -1 +1,8 @@
1
1
  export type { PRNGController, PRNGGroupController } from './controllers';
2
+ export declare enum Algorithm {
3
+ jsf32 = "jsf32",
4
+ mulberry32 = "mulberry32",
5
+ sfc32 = "sfc32",
6
+ splitmix32 = "splitmix32",// Default
7
+ xoshiro128ss = "xoshiro128**"
8
+ }
package/lib/types.js CHANGED
@@ -1 +1,8 @@
1
- export {};
1
+ export var Algorithm;
2
+ (function (Algorithm) {
3
+ Algorithm["jsf32"] = "jsf32";
4
+ Algorithm["mulberry32"] = "mulberry32";
5
+ Algorithm["sfc32"] = "sfc32";
6
+ Algorithm["splitmix32"] = "splitmix32";
7
+ Algorithm["xoshiro128ss"] = "xoshiro128**";
8
+ })(Algorithm || (Algorithm = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "toosoon-prng",
3
- "version": "1.3.0",
4
- "description": "This project provides a `PRNG` instance and a set of `Controllers` for generating pseudo-random values using a seed-based approach and various algorithms",
3
+ "version": "1.5.0",
4
+ "description": "This project provides a PRNG instance and a set of Controllers for generating pseudo-random values using a seed-based approach and various algorithms",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "scripts": {
@@ -28,7 +28,8 @@
28
28
  },
29
29
  "homepage": "https://github.com/toosoon-dev/toosoon-prng#readme",
30
30
  "dependencies": {
31
- "toosoon-gui": "^1.3.0"
31
+ "toosoon-gui": "^1.3.0",
32
+ "toosoon-utils": "^1.4.0"
32
33
  },
33
34
  "devDependencies": {
34
35
  "typescript": "^5.3.3"
@@ -229,9 +229,9 @@ export class ItemController<T = unknown> extends BasePRNGController<T> {
229
229
 
230
230
  export class ObjectPropertyController<T = unknown> extends BasePRNGController<T> {
231
231
  value: T;
232
- object: { [key: string]: T };
232
+ object: Record<string, T>;
233
233
 
234
- constructor(seed: string, object: { [key: string]: T }) {
234
+ constructor(seed: string, object: Record<string, T>) {
235
235
  super(seed);
236
236
 
237
237
  this.object = object;
@@ -379,10 +379,10 @@ export class ItemGroupController<T = unknown> extends BasePRNGGroupController<T>
379
379
  }
380
380
 
381
381
  export class ObjectPropertyGroupController<T = unknown> extends BasePRNGGroupController<T> {
382
- object: { [key: string]: T };
382
+ object: Record<string, T>;
383
383
  controllers: ObjectPropertyController<T>[] = [];
384
384
 
385
- constructor(seed: string, object: { [key: string]: T }) {
385
+ constructor(seed: string, object: Record<string, T>) {
386
386
  super(seed);
387
387
 
388
388
  this.object = object;
package/src/index.ts CHANGED
@@ -17,6 +17,6 @@ export {
17
17
  WeightsGroupController
18
18
  } from './controllers';
19
19
 
20
- export { default, Algorithm } from './prng';
20
+ export { default } from './prng';
21
21
 
22
22
  export type * from './types';
package/src/prng.ts CHANGED
@@ -1,22 +1,16 @@
1
+ import { jsf32, mulberry32, sfc32, splitmix32, xoshiro128ss, random } from 'toosoon-utils/prng';
2
+
1
3
  import { PRNGController } from './controllers';
2
- import { cyrb128, jsf32, mulberry32, sfc32, splitmix32, xoshiro128ss } from './utils';
3
-
4
- export enum Algorithm {
5
- jsf32 = 'jsf32',
6
- mulberry32 = 'mulberry32',
7
- sfc32 = 'sfc32',
8
- splitmix32 = 'splitmix32', // Default
9
- xoshiro128ss = 'xoshiro128**'
10
- }
4
+ import { Algorithm } from './types';
11
5
 
12
6
  /**
13
- * PRNG class
7
+ * Utility class for generating pseudo-random values
14
8
  *
15
9
  * @class PRNG
16
10
  */
17
11
  class PRNG {
18
12
  public seed: string = '';
19
- public algorithm: Algorithm = Algorithm.splitmix32;
13
+ public algorithm: (...args: number[]) => number = splitmix32;
20
14
  public controllers: PRNGController[] = [];
21
15
 
22
16
  /**
@@ -55,7 +49,7 @@ class PRNG {
55
49
  * @param {Algorithm} algorithm Algorithm name
56
50
  */
57
51
  public setAlgorithm(algorithm: Algorithm): void {
58
- this.algorithm = algorithm;
52
+ this.algorithm = this.getAlgorithm(algorithm);
59
53
  this.controllers.forEach((controller) => controller.getValue());
60
54
  }
61
55
 
@@ -67,19 +61,7 @@ class PRNG {
67
61
  * @returns {number}
68
62
  */
69
63
  public random(seed: string): number {
70
- const hashes = cyrb128(this.seed + seed);
71
- switch (this.algorithm) {
72
- case Algorithm.splitmix32:
73
- return splitmix32(hashes[0]);
74
- case Algorithm.jsf32:
75
- return jsf32(hashes[0], hashes[1], hashes[2], hashes[3]);
76
- case Algorithm.mulberry32:
77
- return mulberry32(hashes[0]);
78
- case Algorithm.sfc32:
79
- return sfc32(hashes[0], hashes[1], hashes[2], hashes[3]);
80
- case Algorithm.xoshiro128ss:
81
- return xoshiro128ss(hashes[0], hashes[1], hashes[2], hashes[3]);
82
- }
64
+ return random({ seed: this.seed + seed, algorithm: this.algorithm });
83
65
  }
84
66
 
85
67
  /**
@@ -158,7 +140,7 @@ class PRNG {
158
140
  * @param {object} object Object to pick the property from
159
141
  * @returns {T|undefined} Random item picked
160
142
  */
161
- public randomObjectProperty<T = unknown>(seed: string, object: { [key: string]: T }): T | undefined {
143
+ public randomObjectProperty<T = unknown>(seed: string, object: Record<string, T>): T | undefined {
162
144
  const keys = Object.keys(object);
163
145
  const key = this.randomItem(seed, keys);
164
146
  if (key && object.hasOwnProperty(key)) {
@@ -183,14 +165,35 @@ class PRNG {
183
165
 
184
166
  if (totalWeight <= 0) console.warn('PRNG.randomIndex()', 'Weights must sum to > 0', totalWeight);
185
167
 
186
- let random = this.random(seed) * totalWeight;
168
+ let weight = this.random(seed) * totalWeight;
187
169
  for (let i = 0; i < weights.length; i++) {
188
- if (random < weights[i]) return i;
189
- random -= weights[i];
170
+ if (weight < weights[i]) return i;
171
+ weight -= weights[i];
190
172
  }
191
173
 
192
174
  return 0;
193
175
  }
176
+
177
+ /**
178
+ * Get the PRNG algorithm function by its name
179
+ *
180
+ * @param {Algorithm} algorithm Algorithm name
181
+ * @returns {Function} PRNG algorithm function
182
+ */
183
+ private getAlgorithm(algorithm: Algorithm): (...args: number[]) => number {
184
+ switch (algorithm) {
185
+ case Algorithm.splitmix32:
186
+ return splitmix32;
187
+ case Algorithm.jsf32:
188
+ return jsf32;
189
+ case Algorithm.mulberry32:
190
+ return mulberry32;
191
+ case Algorithm.sfc32:
192
+ return sfc32;
193
+ case Algorithm.xoshiro128ss:
194
+ return xoshiro128ss;
195
+ }
196
+ }
194
197
  }
195
198
 
196
199
  const prng = new PRNG();
package/src/types.ts CHANGED
@@ -1 +1,9 @@
1
1
  export type { PRNGController, PRNGGroupController } from './controllers';
2
+
3
+ export enum Algorithm {
4
+ jsf32 = 'jsf32',
5
+ mulberry32 = 'mulberry32',
6
+ sfc32 = 'sfc32',
7
+ splitmix32 = 'splitmix32', // Default
8
+ xoshiro128ss = 'xoshiro128**'
9
+ }
package/src/utils.ts DELETED
@@ -1,122 +0,0 @@
1
- // Seeding random number generator
2
- // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
3
-
4
- /**
5
- * Produce a 128-bit hash value from a string
6
- *
7
- * @param {string} seed
8
- * @return {number}
9
- */
10
- export function cyrb128(seed: string): number[] {
11
- let h1 = 1779033703;
12
- let h2 = 3144134277;
13
- let h3 = 1013904242;
14
- let h4 = 2773480762;
15
- for (let i = 0, k; i < seed.length; i++) {
16
- k = seed.charCodeAt(i);
17
- h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
18
- h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
19
- h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
20
- h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
21
- }
22
- h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);
23
- h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);
24
- h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);
25
- h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);
26
- return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];
27
- }
28
-
29
- // *********************
30
- // Algorithms
31
- // *********************
32
-
33
- /**
34
- * Simple Fast Counter, Generator with a 128-bit state
35
- *
36
- * @param {number} a
37
- * @param {number} b
38
- * @param {number} c
39
- * @param {number} d
40
- * @return {number}
41
- */
42
- export function sfc32(a: number, b: number, c: number, d: number): number {
43
- a >>>= 0;
44
- b >>>= 0;
45
- c >>>= 0;
46
- d >>>= 0;
47
- let t = (a + b) | 0;
48
- a = b ^ (b >>> 9);
49
- b = (c + (c << 3)) | 0;
50
- c = (c << 21) | (c >>> 11);
51
- d = (d + 1) | 0;
52
- t = (t + d) | 0;
53
- c = (c + t) | 0;
54
- return (t >>> 0) / 4294967296;
55
- }
56
-
57
- /**
58
- * SplitMix32, Generator with a 32-bit state
59
- *
60
- * @param {number} a
61
- * @returns {number}
62
- */
63
- export function splitmix32(a: number): number {
64
- a |= 0;
65
- a = (a + 0x9e3779b9) | 0;
66
- var t = a ^ (a >>> 16);
67
- t = Math.imul(t, 0x21f0aaad);
68
- t = t ^ (t >>> 15);
69
- t = Math.imul(t, 0x735a2d97);
70
- return ((t = t ^ (t >>> 15)) >>> 0) / 4294967296;
71
- }
72
-
73
- /**
74
- * Mulberry32, Generator with a 32-bit state
75
- *
76
- * @param {number} a
77
- * @return {number}
78
- */
79
- export function mulberry32(a: number): number {
80
- let t = (a += 0x6d2b79f5);
81
- t = Math.imul(t ^ (t >>> 15), t | 1);
82
- t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
83
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
84
- }
85
-
86
- /**
87
- * Jenkins' Small Fast, Generator with a 32-bit state
88
- *
89
- * @param {number} a
90
- * @returns {number}
91
- */
92
- export function jsf32(a: number, b: number, c: number, d: number): number {
93
- a |= 0;
94
- b |= 0;
95
- c |= 0;
96
- d |= 0;
97
- let t = (a - ((b << 27) | (b >>> 5))) | 0;
98
- a = b ^ ((c << 17) | (c >>> 15));
99
- b = (c + d) | 0;
100
- c = (d + t) | 0;
101
- d = (a + t) | 0;
102
- return (d >>> 0) / 4294967296;
103
- }
104
-
105
- /**
106
- * xoshiro128**, Generator with a 128-bit state
107
- *
108
- * @param {number} a
109
- * @returns {number}
110
- */
111
- export function xoshiro128ss(a: number, b: number, c: number, d: number): number {
112
- let t = b << 9;
113
- let r = a * 5;
114
- r = ((r << 7) | (r >>> 25)) * 9;
115
- c ^= a;
116
- d ^= b;
117
- b ^= c;
118
- a ^= d;
119
- c ^= t;
120
- d = (d << 11) | (d >>> 21);
121
- return (r >>> 0) / 4294967296;
122
- }