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

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...