Skip to content

Commit fb5e2c2

Browse files
committed
chore(RollTable): 🔧 Increase createRandFn generation speed
1 parent ecc212f commit fb5e2c2

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/utils/RollTable.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class RollTable extends Map {
117117
throw new TypeError(`RollTableError[${this.name}]: Reference "${reference}" Not A Number!`);
118118
}
119119
if (reference > this.max) {
120-
return this.get(this.max);
120+
return super.get(this.max);
121121
}
122122
for (const [key] of this) {
123123
if (reference <= key) {
@@ -197,14 +197,28 @@ class RollTable extends Map {
197197
/** @type {RandFunction} */
198198
let fn;
199199

200-
if (hasSameDigits(max)) {
200+
if (max === 66) {
201+
fn = () => {
202+
let result = mod;
203+
for (let i = 0; i < qty; i++) result += rand(1, 6) * 10 + rand(1, 6);
204+
return result;
205+
};
206+
}
207+
else if (max === 666) {
208+
fn = () => {
209+
let result = mod;
210+
for (let i = 0; i < qty; i++) result += rand(1, 6) * 100 + rand(1, 6) * 10 + rand(1, 6);
211+
return result;
212+
};
213+
}
214+
else if (max > 66 && hasSameDigits(max)) {
201215
// Gets the actual Base. D66 = 6; D88 = 8;
202216
const digit = max % 10;
203217
// Creates sequence for the Base <digit>
204218
const seq = Array(digit).fill().map((x, n) => n + 1).join('');
205219

206220
fn = () => {
207-
let result = 0;
221+
let result = mod;
208222
for (let i = 0; i < qty; i++) {
209223
let seed = rand(1, max);
210224
// Adjusts the seed.
@@ -213,14 +227,14 @@ class RollTable extends Map {
213227
// Converts the seed into a valid reference.
214228
result += +convertToBijective(seed, seq);
215229
}
216-
return result + mod;
230+
return result;
217231
};
218232
}
219233
else if (max > 0) {
220234
fn = () => {
221-
let result = 0;
235+
let result = mod;
222236
for (let i = 0; i < qty; i++) result += rand(1, max);
223-
return result + mod;
237+
return result;
224238
};
225239
}
226240
else {

0 commit comments

Comments
 (0)