Skip to content

Commit

Permalink
better randomNum method
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed Feb 24, 2023
1 parent 3cdcb30 commit d35b480
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/help.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const randomNum = (max = 100): number => Math.floor(Math.random() * max);

export const randomStr = (len: number = 16) => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
Expand All @@ -10,3 +8,9 @@ export const randomStr = (len: number = 16) => {

return result;
};

export const randomNum = (min: number = 1, max: number = 99) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
};

0 comments on commit d35b480

Please sign in to comment.