Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

random number in range js

var min = 10, max = 25;
//inclusive random (can output 25)
var random = Math.round(Math.random() * (max - min) + min);
//exclusive random (max number that can be output is 24, in this case)
var random = Math.floor(Math.random() * (max - min) + min);
//floor takes the number beneath the generated random and round takes
//which ever is the closest to the decimal
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #random #number #range #js
ADD COMMENT
Topic
Name
9+7 =