Skip to content

Commit

Permalink
RC #291 - Adding Numbers class to shared package
Browse files Browse the repository at this point in the history
  • Loading branch information
dleadbetter committed Aug 13, 2024
1 parent 6da17a7 commit 6bec342
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/shared/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export { default as FuzzyDate } from './utils/FuzzyDate';
export { default as Hooks } from './utils/Hooks';
export { default as IIIF } from './utils/IIIF';
export { default as Map } from './utils/Map';
export { default as Numbers } from './utils/Numbers';
export { default as ObjectJs } from './utils/Object';
export { default as String } from './utils/String';
export { default as Timer } from './utils/Timer';
Expand Down
19 changes: 19 additions & 0 deletions packages/shared/src/utils/Numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow

/**
* Returns a random integer between the min (inclusive) and max (exclude) values.
*
* @param min
* @param max
*
* @returns {number}
*/
const getRandomInt = (min, max) => {
const minCeiled = Math.ceil(min);
const maxFloored = Math.floor(max);
return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled);
};

export default {
getRandomInt
};

0 comments on commit 6bec342

Please sign in to comment.