Files
30-seconds-of-code/snippets/randomNumberInRange.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

16 lines
366 B
Markdown

---
title: randomNumberInRange
tags: math,utility,random,beginner
---
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
```