toosoon-prng 1.1.0 → 1.2.1
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 +192 -35
- package/lib/controllers.d.ts +13 -13
- package/lib/controllers.js +38 -44
- package/lib/index.d.ts +1 -2
- package/lib/index.js +2 -25
- package/lib/prng.d.ts +96 -6
- package/lib/prng.js +117 -30
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils.d.ts +11 -4
- package/lib/utils.js +27 -20
- package/package.json +7 -3
- package/src/controllers.ts +14 -14
- package/src/index.ts +1 -2
- package/src/prng.ts +110 -20
- package/src/utils.ts +23 -7
- package/tsconfig.json +2 -1
package/lib/controllers.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __extends = (this && this.__extends) || (function () {
|
|
3
2
|
var extendStatics = function (d, b) {
|
|
4
3
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -14,23 +13,18 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
14
|
};
|
|
16
15
|
})();
|
|
17
|
-
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.WeightsGroupController = exports.ObjectPropertyGroupController = exports.ItemGroupController = exports.HexColorGroupController = exports.IntGroupController = exports.FloatGroupController = exports.SignGroupController = exports.BooleanGroupController = exports.WeightsController = exports.ObjectPropertyController = exports.ItemController = exports.HexColorController = exports.IntController = exports.FloatController = exports.SignController = exports.BooleanController = void 0;
|
|
22
|
-
var prng_1 = __importDefault(require("./prng"));
|
|
16
|
+
import prng from './prng';
|
|
23
17
|
// *********************
|
|
24
18
|
// Abstract controllers
|
|
25
19
|
// *********************
|
|
26
20
|
var BasePRNGController = /** @class */ (function () {
|
|
27
21
|
function BasePRNGController(seed) {
|
|
28
22
|
this.seed = seed;
|
|
29
|
-
|
|
23
|
+
prng.addController(this);
|
|
30
24
|
}
|
|
31
25
|
BasePRNGController.prototype.dispose = function () {
|
|
32
26
|
var _a;
|
|
33
|
-
|
|
27
|
+
prng.removeController(this);
|
|
34
28
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
35
29
|
};
|
|
36
30
|
return BasePRNGController;
|
|
@@ -40,7 +34,7 @@ var BasePRNGGroupController = /** @class */ (function () {
|
|
|
40
34
|
this.controllers = [];
|
|
41
35
|
this.seed = seed;
|
|
42
36
|
}
|
|
43
|
-
BasePRNGGroupController.prototype.
|
|
37
|
+
BasePRNGGroupController.prototype.addGUI = function (gui, min, max, step) {
|
|
44
38
|
this.gui = gui.addFolder(this.seed).close();
|
|
45
39
|
this.guiArgs = { min: min, max: max, step: step };
|
|
46
40
|
return this.gui;
|
|
@@ -51,7 +45,7 @@ var BasePRNGGroupController = /** @class */ (function () {
|
|
|
51
45
|
controller = this.createController(index);
|
|
52
46
|
if (this.gui) {
|
|
53
47
|
controller
|
|
54
|
-
.
|
|
48
|
+
.addGUI(this.gui, this.guiArgs.min, this.guiArgs.max, this.guiArgs.step)
|
|
55
49
|
.name("".concat(this.seed, "-").concat(index));
|
|
56
50
|
}
|
|
57
51
|
this.controllers[index] = controller;
|
|
@@ -78,19 +72,19 @@ var BooleanController = /** @class */ (function (_super) {
|
|
|
78
72
|
_this.value = _this.getValue();
|
|
79
73
|
return _this;
|
|
80
74
|
}
|
|
81
|
-
BooleanController.prototype.
|
|
75
|
+
BooleanController.prototype.addGUI = function (gui) {
|
|
82
76
|
this.gui = gui.add(this, 'value').name(this.seed);
|
|
83
77
|
return this.gui;
|
|
84
78
|
};
|
|
85
79
|
BooleanController.prototype.getValue = function () {
|
|
86
80
|
var _a;
|
|
87
|
-
this.value =
|
|
81
|
+
this.value = prng.randomBoolean(this.seed, this.probability);
|
|
88
82
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
89
83
|
return this.value;
|
|
90
84
|
};
|
|
91
85
|
return BooleanController;
|
|
92
86
|
}(BasePRNGController));
|
|
93
|
-
|
|
87
|
+
export { BooleanController };
|
|
94
88
|
var SignController = /** @class */ (function (_super) {
|
|
95
89
|
__extends(SignController, _super);
|
|
96
90
|
function SignController(seed, probability) {
|
|
@@ -100,19 +94,19 @@ var SignController = /** @class */ (function (_super) {
|
|
|
100
94
|
_this.value = _this.getValue();
|
|
101
95
|
return _this;
|
|
102
96
|
}
|
|
103
|
-
SignController.prototype.
|
|
97
|
+
SignController.prototype.addGUI = function (gui) {
|
|
104
98
|
this.gui = gui.add(this, 'value', [-1, 1]).name(this.seed);
|
|
105
99
|
return this.gui;
|
|
106
100
|
};
|
|
107
101
|
SignController.prototype.getValue = function () {
|
|
108
102
|
var _a;
|
|
109
|
-
this.value =
|
|
103
|
+
this.value = prng.randomSign(this.seed, this.probability);
|
|
110
104
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
111
105
|
return this.value;
|
|
112
106
|
};
|
|
113
107
|
return SignController;
|
|
114
108
|
}(BasePRNGController));
|
|
115
|
-
|
|
109
|
+
export { SignController };
|
|
116
110
|
var FloatController = /** @class */ (function (_super) {
|
|
117
111
|
__extends(FloatController, _super);
|
|
118
112
|
function FloatController(seed, min, max) {
|
|
@@ -124,43 +118,43 @@ var FloatController = /** @class */ (function (_super) {
|
|
|
124
118
|
_this.value = _this.getValue();
|
|
125
119
|
return _this;
|
|
126
120
|
}
|
|
127
|
-
FloatController.prototype.
|
|
121
|
+
FloatController.prototype.addGUI = function (gui, min, max, step) {
|
|
128
122
|
if (step === void 0) { step = 0.01; }
|
|
129
123
|
this.gui = gui.add(this, 'value', min, max, step).name(this.seed);
|
|
130
124
|
return this.gui;
|
|
131
125
|
};
|
|
132
126
|
FloatController.prototype.getValue = function () {
|
|
133
127
|
var _a;
|
|
134
|
-
this.value =
|
|
128
|
+
this.value = prng.randomFloat(this.seed, this.min, this.max);
|
|
135
129
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
136
130
|
return this.value;
|
|
137
131
|
};
|
|
138
132
|
return FloatController;
|
|
139
133
|
}(BasePRNGController));
|
|
140
|
-
|
|
134
|
+
export { FloatController };
|
|
141
135
|
var IntController = /** @class */ (function (_super) {
|
|
142
136
|
__extends(IntController, _super);
|
|
143
137
|
function IntController(seed, min, max) {
|
|
144
138
|
var _this = _super.call(this, seed) || this;
|
|
145
139
|
_this.min = min;
|
|
146
140
|
_this.max = max;
|
|
147
|
-
_this.value =
|
|
141
|
+
_this.value = prng.randomInt(_this.seed, min, max);
|
|
148
142
|
return _this;
|
|
149
143
|
}
|
|
150
|
-
IntController.prototype.
|
|
144
|
+
IntController.prototype.addGUI = function (gui, min, max, step) {
|
|
151
145
|
if (step === void 0) { step = 1; }
|
|
152
146
|
this.gui = gui.add(this, 'value', min, max, step).name(this.seed);
|
|
153
147
|
return this.gui;
|
|
154
148
|
};
|
|
155
149
|
IntController.prototype.getValue = function () {
|
|
156
150
|
var _a;
|
|
157
|
-
this.value =
|
|
151
|
+
this.value = prng.randomInt(this.seed, this.min, this.max);
|
|
158
152
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
159
153
|
return this.value;
|
|
160
154
|
};
|
|
161
155
|
return IntController;
|
|
162
156
|
}(BasePRNGController));
|
|
163
|
-
|
|
157
|
+
export { IntController };
|
|
164
158
|
var HexColorController = /** @class */ (function (_super) {
|
|
165
159
|
__extends(HexColorController, _super);
|
|
166
160
|
function HexColorController(seed) {
|
|
@@ -168,19 +162,19 @@ var HexColorController = /** @class */ (function (_super) {
|
|
|
168
162
|
_this.value = _this.getValue();
|
|
169
163
|
return _this;
|
|
170
164
|
}
|
|
171
|
-
HexColorController.prototype.
|
|
165
|
+
HexColorController.prototype.addGUI = function (gui) {
|
|
172
166
|
this.gui = gui.addColor(this, 'value').name(this.seed);
|
|
173
167
|
return this.gui;
|
|
174
168
|
};
|
|
175
169
|
HexColorController.prototype.getValue = function () {
|
|
176
170
|
var _a;
|
|
177
|
-
this.value =
|
|
171
|
+
this.value = prng.randomHexColor(this.seed);
|
|
178
172
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
179
173
|
return this.value;
|
|
180
174
|
};
|
|
181
175
|
return HexColorController;
|
|
182
176
|
}(BasePRNGController));
|
|
183
|
-
|
|
177
|
+
export { HexColorController };
|
|
184
178
|
var ItemController = /** @class */ (function (_super) {
|
|
185
179
|
__extends(ItemController, _super);
|
|
186
180
|
function ItemController(seed, items) {
|
|
@@ -189,19 +183,19 @@ var ItemController = /** @class */ (function (_super) {
|
|
|
189
183
|
_this.value = _this.getValue();
|
|
190
184
|
return _this;
|
|
191
185
|
}
|
|
192
|
-
ItemController.prototype.
|
|
186
|
+
ItemController.prototype.addGUI = function (gui) {
|
|
193
187
|
this.gui = gui.add(this, 'value', this.items).name(this.seed);
|
|
194
188
|
return this.gui;
|
|
195
189
|
};
|
|
196
190
|
ItemController.prototype.getValue = function () {
|
|
197
191
|
var _a;
|
|
198
|
-
this.value =
|
|
192
|
+
this.value = prng.randomItem(this.seed, this.items);
|
|
199
193
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
200
194
|
return this.value;
|
|
201
195
|
};
|
|
202
196
|
return ItemController;
|
|
203
197
|
}(BasePRNGController));
|
|
204
|
-
|
|
198
|
+
export { ItemController };
|
|
205
199
|
var ObjectPropertyController = /** @class */ (function (_super) {
|
|
206
200
|
__extends(ObjectPropertyController, _super);
|
|
207
201
|
function ObjectPropertyController(seed, object) {
|
|
@@ -210,19 +204,19 @@ var ObjectPropertyController = /** @class */ (function (_super) {
|
|
|
210
204
|
_this.value = _this.getValue();
|
|
211
205
|
return _this;
|
|
212
206
|
}
|
|
213
|
-
ObjectPropertyController.prototype.
|
|
207
|
+
ObjectPropertyController.prototype.addGUI = function (gui) {
|
|
214
208
|
this.gui = gui.add(this, 'value', this.object).name(this.seed);
|
|
215
209
|
return this.gui;
|
|
216
210
|
};
|
|
217
211
|
ObjectPropertyController.prototype.getValue = function () {
|
|
218
212
|
var _a;
|
|
219
|
-
this.value =
|
|
213
|
+
this.value = prng.randomObjectProperty(this.seed, this.object);
|
|
220
214
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
221
215
|
return this.value;
|
|
222
216
|
};
|
|
223
217
|
return ObjectPropertyController;
|
|
224
218
|
}(BasePRNGController));
|
|
225
|
-
|
|
219
|
+
export { ObjectPropertyController };
|
|
226
220
|
var WeightsController = /** @class */ (function (_super) {
|
|
227
221
|
__extends(WeightsController, _super);
|
|
228
222
|
function WeightsController(seed, items) {
|
|
@@ -232,7 +226,7 @@ var WeightsController = /** @class */ (function (_super) {
|
|
|
232
226
|
_this.value = _this.getValue();
|
|
233
227
|
return _this;
|
|
234
228
|
}
|
|
235
|
-
WeightsController.prototype.
|
|
229
|
+
WeightsController.prototype.addGUI = function (gui) {
|
|
236
230
|
this.gui = gui
|
|
237
231
|
.add(this, 'value', this.items.map(function (item) { return item.value; }))
|
|
238
232
|
.name(this.seed);
|
|
@@ -240,14 +234,14 @@ var WeightsController = /** @class */ (function (_super) {
|
|
|
240
234
|
};
|
|
241
235
|
WeightsController.prototype.getValue = function () {
|
|
242
236
|
var _a;
|
|
243
|
-
var index =
|
|
237
|
+
var index = prng.randomIndex(this.seed, this.weights);
|
|
244
238
|
this.value = this.items[index].value;
|
|
245
239
|
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
246
240
|
return this.value;
|
|
247
241
|
};
|
|
248
242
|
return WeightsController;
|
|
249
243
|
}(BasePRNGController));
|
|
250
|
-
|
|
244
|
+
export { WeightsController };
|
|
251
245
|
// *********************
|
|
252
246
|
// Group Controllers
|
|
253
247
|
// *********************
|
|
@@ -264,7 +258,7 @@ var BooleanGroupController = /** @class */ (function (_super) {
|
|
|
264
258
|
};
|
|
265
259
|
return BooleanGroupController;
|
|
266
260
|
}(BasePRNGGroupController));
|
|
267
|
-
|
|
261
|
+
export { BooleanGroupController };
|
|
268
262
|
var SignGroupController = /** @class */ (function (_super) {
|
|
269
263
|
__extends(SignGroupController, _super);
|
|
270
264
|
function SignGroupController(seed, probability) {
|
|
@@ -278,7 +272,7 @@ var SignGroupController = /** @class */ (function (_super) {
|
|
|
278
272
|
};
|
|
279
273
|
return SignGroupController;
|
|
280
274
|
}(BasePRNGGroupController));
|
|
281
|
-
|
|
275
|
+
export { SignGroupController };
|
|
282
276
|
var FloatGroupController = /** @class */ (function (_super) {
|
|
283
277
|
__extends(FloatGroupController, _super);
|
|
284
278
|
function FloatGroupController(seed, min, max) {
|
|
@@ -293,7 +287,7 @@ var FloatGroupController = /** @class */ (function (_super) {
|
|
|
293
287
|
};
|
|
294
288
|
return FloatGroupController;
|
|
295
289
|
}(BasePRNGGroupController));
|
|
296
|
-
|
|
290
|
+
export { FloatGroupController };
|
|
297
291
|
var IntGroupController = /** @class */ (function (_super) {
|
|
298
292
|
__extends(IntGroupController, _super);
|
|
299
293
|
function IntGroupController(seed, min, max) {
|
|
@@ -308,7 +302,7 @@ var IntGroupController = /** @class */ (function (_super) {
|
|
|
308
302
|
};
|
|
309
303
|
return IntGroupController;
|
|
310
304
|
}(BasePRNGGroupController));
|
|
311
|
-
|
|
305
|
+
export { IntGroupController };
|
|
312
306
|
var HexColorGroupController = /** @class */ (function (_super) {
|
|
313
307
|
__extends(HexColorGroupController, _super);
|
|
314
308
|
function HexColorGroupController() {
|
|
@@ -324,7 +318,7 @@ var HexColorGroupController = /** @class */ (function (_super) {
|
|
|
324
318
|
};
|
|
325
319
|
return HexColorGroupController;
|
|
326
320
|
}(BasePRNGGroupController));
|
|
327
|
-
|
|
321
|
+
export { HexColorGroupController };
|
|
328
322
|
var ItemGroupController = /** @class */ (function (_super) {
|
|
329
323
|
__extends(ItemGroupController, _super);
|
|
330
324
|
function ItemGroupController(seed, items) {
|
|
@@ -338,7 +332,7 @@ var ItemGroupController = /** @class */ (function (_super) {
|
|
|
338
332
|
};
|
|
339
333
|
return ItemGroupController;
|
|
340
334
|
}(BasePRNGGroupController));
|
|
341
|
-
|
|
335
|
+
export { ItemGroupController };
|
|
342
336
|
var ObjectPropertyGroupController = /** @class */ (function (_super) {
|
|
343
337
|
__extends(ObjectPropertyGroupController, _super);
|
|
344
338
|
function ObjectPropertyGroupController(seed, object) {
|
|
@@ -352,7 +346,7 @@ var ObjectPropertyGroupController = /** @class */ (function (_super) {
|
|
|
352
346
|
};
|
|
353
347
|
return ObjectPropertyGroupController;
|
|
354
348
|
}(BasePRNGGroupController));
|
|
355
|
-
|
|
349
|
+
export { ObjectPropertyGroupController };
|
|
356
350
|
var WeightsGroupController = /** @class */ (function (_super) {
|
|
357
351
|
__extends(WeightsGroupController, _super);
|
|
358
352
|
function WeightsGroupController(seed, items) {
|
|
@@ -366,4 +360,4 @@ var WeightsGroupController = /** @class */ (function (_super) {
|
|
|
366
360
|
};
|
|
367
361
|
return WeightsGroupController;
|
|
368
362
|
}(BasePRNGGroupController));
|
|
369
|
-
|
|
363
|
+
export { WeightsGroupController };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { BooleanController, SignController, IntController, FloatController, HexColorController, ItemController, ObjectPropertyController, WeightsController, BooleanGroupController, SignGroupController, IntGroupController, FloatGroupController, HexColorGroupController, ItemGroupController, ObjectPropertyGroupController, WeightsGroupController } from './controllers';
|
|
2
2
|
export type { PRNGController, PRNGGroupController } from './controllers';
|
|
3
|
-
export { default } from './prng';
|
|
4
|
-
export type * from './prng';
|
|
3
|
+
export { default, Algorithm } from './prng';
|
package/lib/index.js
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = exports.WeightsGroupController = exports.ObjectPropertyGroupController = exports.ItemGroupController = exports.HexColorGroupController = exports.FloatGroupController = exports.IntGroupController = exports.SignGroupController = exports.BooleanGroupController = exports.WeightsController = exports.ObjectPropertyController = exports.ItemController = exports.HexColorController = exports.FloatController = exports.IntController = exports.SignController = exports.BooleanController = void 0;
|
|
7
|
-
var controllers_1 = require("./controllers");
|
|
8
|
-
Object.defineProperty(exports, "BooleanController", { enumerable: true, get: function () { return controllers_1.BooleanController; } });
|
|
9
|
-
Object.defineProperty(exports, "SignController", { enumerable: true, get: function () { return controllers_1.SignController; } });
|
|
10
|
-
Object.defineProperty(exports, "IntController", { enumerable: true, get: function () { return controllers_1.IntController; } });
|
|
11
|
-
Object.defineProperty(exports, "FloatController", { enumerable: true, get: function () { return controllers_1.FloatController; } });
|
|
12
|
-
Object.defineProperty(exports, "HexColorController", { enumerable: true, get: function () { return controllers_1.HexColorController; } });
|
|
13
|
-
Object.defineProperty(exports, "ItemController", { enumerable: true, get: function () { return controllers_1.ItemController; } });
|
|
14
|
-
Object.defineProperty(exports, "ObjectPropertyController", { enumerable: true, get: function () { return controllers_1.ObjectPropertyController; } });
|
|
15
|
-
Object.defineProperty(exports, "WeightsController", { enumerable: true, get: function () { return controllers_1.WeightsController; } });
|
|
16
|
-
Object.defineProperty(exports, "BooleanGroupController", { enumerable: true, get: function () { return controllers_1.BooleanGroupController; } });
|
|
17
|
-
Object.defineProperty(exports, "SignGroupController", { enumerable: true, get: function () { return controllers_1.SignGroupController; } });
|
|
18
|
-
Object.defineProperty(exports, "IntGroupController", { enumerable: true, get: function () { return controllers_1.IntGroupController; } });
|
|
19
|
-
Object.defineProperty(exports, "FloatGroupController", { enumerable: true, get: function () { return controllers_1.FloatGroupController; } });
|
|
20
|
-
Object.defineProperty(exports, "HexColorGroupController", { enumerable: true, get: function () { return controllers_1.HexColorGroupController; } });
|
|
21
|
-
Object.defineProperty(exports, "ItemGroupController", { enumerable: true, get: function () { return controllers_1.ItemGroupController; } });
|
|
22
|
-
Object.defineProperty(exports, "ObjectPropertyGroupController", { enumerable: true, get: function () { return controllers_1.ObjectPropertyGroupController; } });
|
|
23
|
-
Object.defineProperty(exports, "WeightsGroupController", { enumerable: true, get: function () { return controllers_1.WeightsGroupController; } });
|
|
24
|
-
var prng_1 = require("./prng");
|
|
25
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(prng_1).default; } });
|
|
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';
|
package/lib/prng.d.ts
CHANGED
|
@@ -1,30 +1,120 @@
|
|
|
1
1
|
import { PRNGController } from './controllers';
|
|
2
|
-
export declare enum
|
|
2
|
+
export declare enum Algorithm {
|
|
3
3
|
jsf32 = "jsf32",
|
|
4
4
|
mulberry32 = "mulberry32",
|
|
5
5
|
sfc32 = "sfc32",
|
|
6
|
+
splitmix32 = "splitmix32",// Default
|
|
6
7
|
xoshiro128ss = "xoshiro128**"
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* PRNG class
|
|
11
|
+
*
|
|
12
|
+
* @class PRNG
|
|
13
|
+
*/
|
|
8
14
|
declare class PRNG {
|
|
9
15
|
seed: string;
|
|
10
|
-
|
|
16
|
+
algorithm: Algorithm;
|
|
11
17
|
controllers: PRNGController[];
|
|
12
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Add a controller to this PRNG
|
|
20
|
+
*
|
|
21
|
+
* @param {PRNGController} controller
|
|
22
|
+
*/
|
|
13
23
|
addController(controller: PRNGController): void;
|
|
24
|
+
/**
|
|
25
|
+
* Remove a controller from this PRNG
|
|
26
|
+
*
|
|
27
|
+
* @param {PRNGController} controller
|
|
28
|
+
*/
|
|
14
29
|
removeController(controller: PRNGController): void;
|
|
30
|
+
/**
|
|
31
|
+
* Set this PRNG seed
|
|
32
|
+
*
|
|
33
|
+
* @param {string} seed
|
|
34
|
+
*/
|
|
15
35
|
setSeed(seed: string): void;
|
|
16
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Set this PRNG algorithm for generating pseudo-random values
|
|
38
|
+
*
|
|
39
|
+
* @param {Algorithm} algorithm Algorithm name
|
|
40
|
+
*/
|
|
41
|
+
setAlgorithm(algorithm: Algorithm): void;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a pseudo-random number in the interval [0, 1]
|
|
44
|
+
* PRNG equivalent of `Math.random()`
|
|
45
|
+
*
|
|
46
|
+
* @param {string} seed
|
|
47
|
+
* @returns {number}
|
|
48
|
+
*/
|
|
17
49
|
random(seed: string): number;
|
|
50
|
+
/**
|
|
51
|
+
* Generate a pseudo-random boolean (true or false)
|
|
52
|
+
*
|
|
53
|
+
* @param {string} seed
|
|
54
|
+
* @param {number} [probability=0.5] Probability to get `true`
|
|
55
|
+
* @returns {boolean} Either `true` or `false`
|
|
56
|
+
*/
|
|
18
57
|
randomBoolean(seed: string, probability?: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Generate a pseudo-random sign (1 or -1)
|
|
60
|
+
*
|
|
61
|
+
* @param {string} seed
|
|
62
|
+
* @param {number} [probability=0.5] Probability to get 1
|
|
63
|
+
* @returns {number} Either 1 or -1
|
|
64
|
+
*/
|
|
19
65
|
randomSign(seed: string, probability?: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* Generate a pseudo-random floating-point number within a specified range
|
|
68
|
+
*
|
|
69
|
+
* @param {string} seed
|
|
70
|
+
* @param {number} [min=0] Minimum boundary
|
|
71
|
+
* @param {number} [max=1] Maximum boundary
|
|
72
|
+
* @param {number} [precision=2] Number of digits after the decimal point
|
|
73
|
+
* @returns {number} Generated float
|
|
74
|
+
*/
|
|
20
75
|
randomFloat(seed: string, min?: number, max?: number, precision?: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* Generate a pseudo-random integer number within a specified range
|
|
78
|
+
*
|
|
79
|
+
* @param {string} seed
|
|
80
|
+
* @param {number} min Minimum boundary
|
|
81
|
+
* @param {number} max Maximum boundary
|
|
82
|
+
* @returns {number} Generated integer
|
|
83
|
+
*/
|
|
21
84
|
randomInt(seed: string, min: number, max: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* Generate a pseudo-random hexadecimal color
|
|
87
|
+
*
|
|
88
|
+
* @param {string} seed
|
|
89
|
+
* @returns {string} Generated hexadecimal color
|
|
90
|
+
*/
|
|
22
91
|
randomHexColor(seed: string): string;
|
|
23
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Pick a pseudo-random item from a given array
|
|
94
|
+
*
|
|
95
|
+
* @param {string} seed
|
|
96
|
+
* @param {T[]} array Array to pick the item from
|
|
97
|
+
* @returns {T|undefined} Random item picked
|
|
98
|
+
*/
|
|
99
|
+
randomItem<T = unknown>(seed: string, array: T[]): T | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Pick a pseudo-random property value from a given object
|
|
102
|
+
*
|
|
103
|
+
* @param {string} seed
|
|
104
|
+
* @param {object} object Object to pick the property from
|
|
105
|
+
* @returns {T|undefined} Random item picked
|
|
106
|
+
*/
|
|
24
107
|
randomObjectProperty<T = unknown>(seed: string, object: {
|
|
25
108
|
[key: string]: T;
|
|
26
109
|
}): T | undefined;
|
|
27
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Select a pseudo-random index from an array of weighted items
|
|
112
|
+
*
|
|
113
|
+
* @param {string} seed
|
|
114
|
+
* @param {number[]} weights Array of weights
|
|
115
|
+
* @returns {number} Random index based on weights
|
|
116
|
+
*/
|
|
117
|
+
randomIndex(seed: string, weights: number[]): number;
|
|
28
118
|
}
|
|
29
119
|
declare const prng: PRNG;
|
|
30
120
|
export default prng;
|