Kebab file names
This commit is contained in:
19
snippets/random-number-in-range.md
Normal file
19
snippets/random-number-in-range.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
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
|
||||
```
|
||||
Reference in New Issue
Block a user