1.0.2 • Published 2 years ago

@codebundlesbyvik/number-operations v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

number-operations

npm npm - downloads per week

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 on includeMax, the returned integer will be either equal to or below this number.
  • includeMax (Boolean): Whether or not to include max when generating the integer. Default is undefined, which functions as false.

Usage

getRandomIntUnder(10)
// > 7

getRandomIntUnder(10, true)
// > 10

License

MIT © Viktor Chin-Kon-Sung