Mirgorod - 8 months ago 54

Javascript Question

Is there a way to generate a random number in a specified range (e.g. from 1 to 6: 1, 2, 3, 4, 5, or 6) in JavaScript?

Answer

If you wanted to get between 1 and 6, you would calculate:

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

Where:

- 1 is the start number
- 6 is the number of possible results (1 + start
*(6)*- end*(1)*)