30-seconds-of-code
Version:
A collection of useful JavaScript snippets.
14 lines (9 loc) • 321 B
Markdown
### randomNumberInRange
Returns a random number in the specified range.
Use `Math.random()` to generate a random value, map it to the desired range using multiplication.
```js
const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
```
```js
randomNumberInRange(2, 10); // 6.0211363285087005
```