Skip to content

Commit

Permalink
Create random-integer-in-range.md
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks authored Dec 12, 2017
1 parent e602ba0 commit ea98b55
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions snippets/random-integer-in-range.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Random integer in range

Use `Math.random()` to generate a random number and map it to the desired range, using `Math.floor()` to make it an integer.

```js
const randomIntegerInRange = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;
// randomIntegerInRange(0, 5) -> 2
```

0 comments on commit ea98b55

Please sign in to comment.