toosoon-prng 1.0.1 → 1.0.2
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 +49 -17
- package/package.json +1 -1
- package/src/controllers.ts +9 -9
- package/src/prng.ts +1 -1
package/README.md
CHANGED
|
@@ -138,38 +138,70 @@ prng.randomIndex(seed: string, weights?: number[]) => number;
|
|
|
138
138
|
|
|
139
139
|
## PRNG Controllers
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
```ts
|
|
142
|
+
class BooleanController(seed: string, probability?: number);
|
|
143
|
+
```
|
|
142
144
|
|
|
143
|
-
|
|
145
|
+
```ts
|
|
146
|
+
class SignController(seed: string, probability?: number);
|
|
147
|
+
```
|
|
144
148
|
|
|
145
|
-
|
|
149
|
+
```ts
|
|
150
|
+
class FloatController(seed: string, min?: number, max?: number);
|
|
151
|
+
```
|
|
146
152
|
|
|
147
|
-
|
|
153
|
+
```ts
|
|
154
|
+
class IntController(seed: string, min: number, max: number);
|
|
155
|
+
```
|
|
148
156
|
|
|
149
|
-
|
|
157
|
+
```ts
|
|
158
|
+
class HexColorController(seed: string);
|
|
159
|
+
```
|
|
150
160
|
|
|
151
|
-
|
|
161
|
+
```ts
|
|
162
|
+
class ItemController<T>(seed: string, items: T[]);
|
|
163
|
+
```
|
|
152
164
|
|
|
153
|
-
|
|
165
|
+
```ts
|
|
166
|
+
class ObjectPropertyController<T>(seed: string, object: object);
|
|
167
|
+
```
|
|
154
168
|
|
|
155
|
-
|
|
169
|
+
```ts
|
|
170
|
+
class WeightsController<T>(seed: string, items: Array<{ weight: number; value: T }>);
|
|
171
|
+
```
|
|
156
172
|
|
|
157
|
-
|
|
173
|
+
```ts
|
|
174
|
+
class BooleanGroupController(seed: string, probability: number);
|
|
175
|
+
```
|
|
158
176
|
|
|
159
|
-
|
|
177
|
+
```ts
|
|
178
|
+
class SignGroupController(seed: string, probability: number);
|
|
179
|
+
```
|
|
160
180
|
|
|
161
|
-
|
|
181
|
+
```ts
|
|
182
|
+
class FloatGroupController(seed: string, min: number, max: number);
|
|
183
|
+
```
|
|
162
184
|
|
|
163
|
-
|
|
185
|
+
```ts
|
|
186
|
+
class IntGroupController(seed: string, min: number, max: number);
|
|
187
|
+
```
|
|
164
188
|
|
|
165
|
-
|
|
189
|
+
```ts
|
|
190
|
+
class HexColorGroupController(seed: string);
|
|
191
|
+
```
|
|
166
192
|
|
|
167
|
-
|
|
193
|
+
```ts
|
|
194
|
+
class ItemGroupController<T>(seed: string, items: T[]);
|
|
195
|
+
```
|
|
168
196
|
|
|
169
|
-
|
|
197
|
+
```ts
|
|
198
|
+
class ObjectPropertyGroupController<T>(seed: string, object: object);
|
|
199
|
+
```
|
|
170
200
|
|
|
171
|
-
|
|
201
|
+
```ts
|
|
202
|
+
class WeightsGroupController<T>(seed: string, items: Array<{ weight: number; value: T }>);
|
|
203
|
+
```
|
|
172
204
|
|
|
173
205
|
## License
|
|
174
206
|
|
|
175
|
-
MIT License, see [LICENSE](https://github.com/toosoon-dev/toosoon-
|
|
207
|
+
MIT License, see [LICENSE](https://github.com/toosoon-dev/toosoon-prng/tree/master/LICENSE) for details
|
package/package.json
CHANGED
package/src/controllers.ts
CHANGED
|
@@ -102,7 +102,7 @@ export class BooleanController extends BasePRNGController<boolean> {
|
|
|
102
102
|
value: boolean;
|
|
103
103
|
probability: number;
|
|
104
104
|
|
|
105
|
-
constructor(seed: string, probability = 0.5) {
|
|
105
|
+
constructor(seed: string, probability: number = 0.5) {
|
|
106
106
|
super(seed);
|
|
107
107
|
|
|
108
108
|
this.probability = probability;
|
|
@@ -125,7 +125,7 @@ export class SignController extends BasePRNGController<number> {
|
|
|
125
125
|
value: number;
|
|
126
126
|
probability: number;
|
|
127
127
|
|
|
128
|
-
constructor(seed: string, probability = 0.5) {
|
|
128
|
+
constructor(seed: string, probability: number = 0.5) {
|
|
129
129
|
super(seed);
|
|
130
130
|
|
|
131
131
|
this.probability = probability;
|
|
@@ -149,7 +149,7 @@ export class FloatController extends BasePRNGController<number> {
|
|
|
149
149
|
min: number;
|
|
150
150
|
max: number;
|
|
151
151
|
|
|
152
|
-
constructor(seed: string, min = 0, max = 1) {
|
|
152
|
+
constructor(seed: string, min: number = 0, max: number = 1) {
|
|
153
153
|
super(seed);
|
|
154
154
|
|
|
155
155
|
this.min = min;
|
|
@@ -174,7 +174,7 @@ export class IntController extends BasePRNGController<number> {
|
|
|
174
174
|
min: number;
|
|
175
175
|
max: number;
|
|
176
176
|
|
|
177
|
-
constructor(seed: string, min
|
|
177
|
+
constructor(seed: string, min: number, max: number) {
|
|
178
178
|
super(seed);
|
|
179
179
|
|
|
180
180
|
this.min = min;
|
|
@@ -240,9 +240,9 @@ export class ItemController<T = unknown> extends BasePRNGController<T> {
|
|
|
240
240
|
|
|
241
241
|
export class ObjectPropertyController<T = unknown> extends BasePRNGController<T> {
|
|
242
242
|
value: T;
|
|
243
|
-
object:
|
|
243
|
+
object: { [key: string]: T };
|
|
244
244
|
|
|
245
|
-
constructor(seed: string, object:
|
|
245
|
+
constructor(seed: string, object: { [key: string]: T }) {
|
|
246
246
|
super(seed);
|
|
247
247
|
|
|
248
248
|
this.object = object;
|
|
@@ -255,7 +255,7 @@ export class ObjectPropertyController<T = unknown> extends BasePRNGController<T>
|
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
getValue() {
|
|
258
|
-
this.value = prng.randomObjectProperty(this.seed, this.object) as T;
|
|
258
|
+
this.value = prng.randomObjectProperty<T>(this.seed, this.object) as T;
|
|
259
259
|
this.gui?.updateDisplay();
|
|
260
260
|
return this.value;
|
|
261
261
|
}
|
|
@@ -390,10 +390,10 @@ export class ItemGroupController<T = unknown> extends BasePRNGGroupController<T>
|
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
export class ObjectPropertyGroupController<T = unknown> extends BasePRNGGroupController<T> {
|
|
393
|
-
object:
|
|
393
|
+
object: { [key: string]: T };
|
|
394
394
|
controllers: ObjectPropertyController<T>[] = [];
|
|
395
395
|
|
|
396
|
-
constructor(seed: string, object:
|
|
396
|
+
constructor(seed: string, object: { [key: string]: T }) {
|
|
397
397
|
super(seed);
|
|
398
398
|
|
|
399
399
|
this.object = object;
|
package/src/prng.ts
CHANGED
|
@@ -75,7 +75,7 @@ class PRNG {
|
|
|
75
75
|
return array[this.randomInt(seed, 0, array.length - 1)];
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
public randomObjectProperty(seed: string, object:
|
|
78
|
+
public randomObjectProperty<T = unknown>(seed: string, object: { [key: string]: T }): T | undefined {
|
|
79
79
|
const keys = Object.keys(object);
|
|
80
80
|
const key = this.randomItem(seed, keys);
|
|
81
81
|
if (key && object.hasOwnProperty(key)) {
|