Update snippet descriptions
This commit is contained in:
@ -3,13 +3,17 @@ title: randomIntArrayInRange
|
||||
tags: math,random,intermediate
|
||||
---
|
||||
|
||||
Returns an array of n random integers in the specified range.
|
||||
Generates an array of `n` random integers in the specified range.
|
||||
|
||||
- Use `Array.from()` to create an empty array of the specific length, `Math.random()` to generate a random number and map it to the desired range, using `Math.floor()` to make it an integer.
|
||||
- Use `Array.from()` to create an empty array of the specific length.
|
||||
- Use `Math.random()` to generate random numbers and map them to the desired range, using `Math.floor()` to make them integers.
|
||||
|
||||
```js
|
||||
const randomIntArrayInRange = (min, max, n = 1) =>
|
||||
Array.from({ length: n }, () => Math.floor(Math.random() * (max - min + 1)) + min);
|
||||
Array.from(
|
||||
{ length: n },
|
||||
() => Math.floor(Math.random() * (max - min + 1)) + min
|
||||
);
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user