Skip to content

Commit

Permalink
Revert "make max inclusive in randomInt, and add more iterations …
Browse files Browse the repository at this point in the history
…to tests"

This reverts commit 7e7e659.
  • Loading branch information
netroy committed Jun 19, 2024
1 parent 2f3e141 commit 7e5d6d6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/workflow/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ export function randomInt(min: number, max: number): number;
* Generates a random integer within a specified range.
*
* @param {number} min - The lower bound of the range. If `max` is not provided, this value is used as the upper bound and the lower bound is set to 0.
* @param {number} [max] - The upper bound of the range, inclusive.
* @param {number} [max] - The upper bound of the range.
* @returns {number} A random integer within the specified range.
*/
export function randomInt(min: number, max?: number): number {
if (max === undefined) {
max = min;
min = 0;
}
return min + (crypto.getRandomValues(new Uint32Array(1))[0] % (max - min + 1));
return min + (crypto.getRandomValues(new Uint32Array(1))[0] % (max - min));
}

export function randomString(length: number): string;
Expand All @@ -208,7 +208,7 @@ export function randomString(minLength: number, maxLength: number): string;
* @returns {string} A random alphanumeric string of the specified length or within the specified range of lengths.
*/
export function randomString(minLength: number, maxLength?: number): string {
const length = maxLength === undefined ? minLength : randomInt(minLength, maxLength);
const length = maxLength === undefined ? minLength : randomInt(minLength, maxLength + 1);
return [...crypto.getRandomValues(new Uint32Array(length))]
.map((byte) => ALPHABET[byte % ALPHABET.length])
.join('');
Expand Down

0 comments on commit 7e5d6d6

Please sign in to comment.