Skip to content

Instantly share code, notes, and snippets.

@fmtarif
Created October 20, 2014 10:57
Show Gist options
  • Save fmtarif/2e29770c312baa21326b to your computer and use it in GitHub Desktop.
Save fmtarif/2e29770c312baa21326b to your computer and use it in GitHub Desktop.
#js return a random number from a range in javascript
var max = 50,
min = 10;
var random = Math.floor(Math.random() * (max-min) + min) //will return a random int within the range min to max
alert(random);
//so if min is 0 then it simply becomes
//Math.floor(Math.random() * max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment