# Generate a random number between two numbers in JavaScript

> Learn how to generate a random number between two values in JavaScript by combining Math.random() and Math.floor(), for example to pick a number from 1 to 6.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2018-10-20 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-generate-random-number-between/

Use a combination of `Math.floor()` and `Math.random()`.

This simple one line of code will return you a number between 1 and 6 (both included):

```js
Math.floor(Math.random() * 6 + 1)
```

There are 6 possible outcomes here: 1, 2, 3, 4, 5, 6.
