Can you write a random integers function to print integers with in a range?

Answer Posted / hrpatelsoft@gmail.com

function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
randomInteger(1, 100); // returns a random integer from 1 to 100
randomInteger(1, 1000); // returns a random integer from 1 to 1000

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is decodeuri() in javascript?

718


What is difference between deep and shallow object coping in javascript?

718


How does typeof operator work?

760


What is Number object in JavaScript?

738


Does javascript support foreach loop?

711


Taking a developer's perspective, do you think that that javascript is easy to learn and use?

683


What is output of “20” + 20? In javascript?

671


Why do we need currying?

631


What is the difference between ‘function declaration’ and ‘function expression’?

722


How would you compare two objects in JavaScript?

708


Is javascript case sensitive language?

751


What is the difference between JavaScript and jscript?

761


Are there any iphone Institutes which also train iphone automation testing in Hyderabad?

1762


Is there any ide for javascript?

717


What is meaning of === in javascript?

645