Nest all content into snippets
This commit is contained in:
20
snippets/js/s/random-number-in-range.md
Normal file
20
snippets/js/s/random-number-in-range.md
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
title: Random number in range
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [math,random]
|
||||
cover: white-laptop
|
||||
dateModified: 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