Files
30-seconds-of-code/snippets/randomNumberInRange.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

19 lines
439 B
Markdown

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