Generate a random integer in Javascript (ES6), within a given range.
npm install @dmhtoo/random-intThis package is compatible with Typescript
> npm install random-int --save
or
> yarn add random-int
---
> randomInt(low, high);
- low:
Optional minimum value (included). This defaults to 1.
- high:
Optional maximum value (included). This defaults to 100.
- randomInt will return a randomly generated Integer, including the low and high limits.
---
Import the randomInt function
```
import { randomInt } from "@dmhtoo/random-int";
or
``
const { randomInt } = require("@dmhtoo/random-int")
Sample implementations
`
// Returns a random integer between default limits of 1 and 100, inclusive.
const myRandomInteger = randomInt();
// Returns a random integer between 1 and 10, inclusive.
const myRandomInteger = randomInt(1, 10);
``
---
- W3Schools Javascript Random
- MDN Math.random
- MDN Math.floor