mirror of
https://github.com/maciejpedzich/racemash.git
synced 2024-11-27 16:15:47 +01:00
Convert randomNumber composable to utility
This commit is contained in:
parent
0719efab93
commit
e2566c3d32
@ -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);
|
|
||||||
};
|
|
||||||
}
|
|
5
src/utils/randomNumber.ts
Normal file
5
src/utils/randomNumber.ts
Normal 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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user