How to create a random number in javascript

To create a random number in javascript you can use the following snippet.

Sample JS

var random=Math.floor((Math.random() * 10) + 1);

Result
A random number between 1 and 10.

fore more informations see W3Schools JavaScript random() Method

Please Share us:
Please rate this snippet

2 thoughts on “How to create a random number in javascript

Leave a Reply