From 7e5d6d6f44d4fa71f64f54f5e4a74c3d00e5d0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 19 Jun 2024 11:06:26 +0200 Subject: [PATCH] Revert "make `max` inclusive in `randomInt`, and add more iterations to tests" This reverts commit 7e7e6595a13a585516dae79033d6035f58fd4e85. --- packages/workflow/src/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/workflow/src/utils.ts b/packages/workflow/src/utils.ts index 30c6ad09918fc..054a896d16024 100644 --- a/packages/workflow/src/utils.ts +++ b/packages/workflow/src/utils.ts @@ -187,7 +187,7 @@ 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 { @@ -195,7 +195,7 @@ export function randomInt(min: number, max?: number): number { 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; @@ -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('');