Convert randomNumber composable to utility

This commit is contained in:
Maciej Pędzich 2023-06-08 18:55:45 +02:00
parent 0719efab93
commit e2566c3d32
2 changed files with 5 additions and 12 deletions

View File

@ -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);
};
}

View File

@ -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);
}