Files
30-seconds-of-code/snippets/randomNumberInRange.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

20 lines
453 B
Markdown

---
title: Random number in range
tags: math,random
cover: white-laptop
firstSeen: 2017-12-17T17:55:51+02:00
lastUpdated: 2020-10-22T20:24:04+03:00
---
Generates 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
```