1.0.2 • Published 2 years ago
@codebundlesbyvik/number-operations v1.0.2
number-operations
JavaScript helper functions for number operations.
Installation
// Install package from npm
npm install @codebundlesbyvik/number-operations
import getRandomIntUnder from "@codebundlesbyvik/number-operations";
Functions
getRandomIntUnder(max, includeMax)
Generate and return a random integer below a given number.
⚠️ Makes use of Math.random(), which ISN'T cryptographically secure. Do NOT use this for generating secure, random integers. ⚠️
Parameters
* indicates required
- *
max
(Number
): Depending onincludeMax
, the returned integer will be either equal to or below this number. includeMax
(Boolean
): Whether or not to includemax
when generating the integer. Default is undefined, which functions asfalse
.
Usage
getRandomIntUnder(10)
// > 7
getRandomIntUnder(10, true)
// > 10
License
MIT © Viktor Chin-Kon-Sung