JavaScript method to return random number in a range (exclusive of the max limit)

Took 3 minutes and 21 seconds to code JavaScript method to return random number in a range exclusive of the max limit. Here is the code snippet.

Code:

function randomMaxExclusive(min, max) {
x = Math.floor((Math.random() * max - min) + min);
return x;
}

x = randomMaxExclusive(0, 10)
document.write(x);

Result:

4

No comments:

Post a Comment

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...