JavaScript : random number range
floatVal - optional, without it, the function will return an integer; it represents the number of decimal points; precision
function randomRange(minVal, maxVal, floatVal) {
var randVal = minVal+(Math.random()*(maxVal-minVal));
return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}
var randVal = minVal+(Math.random()*(maxVal-minVal));
return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}
floatVal - optional, without it, the function will return an integer; it represents the number of decimal points; precision
No comments:
Post a Comment