diff --git a/app/src/shared/utils.ts b/app/src/shared/utils.ts index 4464333..d8f30d1 100644 --- a/app/src/shared/utils.ts +++ b/app/src/shared/utils.ts @@ -6,4 +6,17 @@ export function countChar(str: string, char: string): number { // Generate a 6 character random ID export function randomId(): string { return Math.random().toString(36).slice(7) +} + +// rng(1, 5) #=> result can be 1 2 3 4 or 5 +// rng(2) #=> result can be 1 or 2 +export function rng(min: number, max = 0) { + if (max === 0) { + max = min + min = 1 + } + + min = Math.ceil(min) + max = Math.floor(max) + return Math.floor(Math.random() * (max - min + 1)) + min } \ No newline at end of file