diff --git a/src/composables/useRandomNumber.ts b/src/composables/useRandomNumber.ts deleted file mode 100644 index 1149ed9..0000000 --- a/src/composables/useRandomNumber.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Why not a standalone randomNumber function? -// I just couldn't be bothered creating a separate utils folder or installing a new package. - -export function useRandomNumber() { - // Shamelessly stolen from: - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_integer_between_two_values_inclusive - return (min: number, max: number) => { - min = Math.ceil(min); - max = Math.floor(max); - return Math.floor(Math.random() * (max - min + 1) + min); - }; -} diff --git a/src/utils/randomNumber.ts b/src/utils/randomNumber.ts new file mode 100644 index 0000000..af96dc2 --- /dev/null +++ b/src/utils/randomNumber.ts @@ -0,0 +1,5 @@ +export function randomNumber(min: number, max: number) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1) + min); +}