Skip to content

Commit

Permalink
Refactor getRandomInt
Browse files Browse the repository at this point in the history
  • Loading branch information
puehringer committed Nov 9, 2023
1 parent 5ac1132 commit afe4fd7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/base/BaseUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class BaseUtils {
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
* See: https://stackoverflow.com/a/1527820/2549748
*/
public static getRandomInt(min, max) {
private static getRandomInt(min, max) {
min = Math.ceil(min);

Check warning on line 120 in src/base/BaseUtils.ts

View workflow job for this annotation

GitHub Actions / build / build-node

Assignment to function parameter 'min'
max = Math.floor(max);

Check warning on line 121 in src/base/BaseUtils.ts

View workflow job for this annotation

GitHub Actions / build / build-node

Assignment to function parameter 'max'
return Math.floor(Math.random() * (max - min + 1)) + min;
Expand All @@ -137,13 +137,13 @@ export class BaseUtils {

while (integers.length !== n) {
// skipped if n = max+1 --> all integers between 0 and max
integers.splice(getRandomInt(0, integers.length), 1); // definetly one hit per iteration
integers.splice(BaseUtils.getRandomInt(0, integers.length), 1); // definetly one hit per iteration
}
return integers;
}
const integers = [];
while (integers.length < n) {
const integer = getRandomInt(0, max);
const integer = BaseUtils.getRandomInt(0, max);
if (integers.indexOf(integer) === -1) {
// not every iteration might add an element
integers.push(integer);
Expand Down

0 comments on commit afe4fd7

Please sign in to comment.