Returns a random number between N and M - Node.js Number

Node.js examples for Number:Random Number

Description

Returns a random number between N and M

Demo Code


// shuffle//from w w w .  ja v a  2s  .  c om
Array.prototype.shuffle = function(){ 
    for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
    return this;
};
// Global object to wrap logic
var Lottery = {};

/**
 * Returns a random number between N and M
 **/
Lottery.randomBetween = function(N,M) {
    return Math.floor(M + (1+N-M)*Math.random());
};

Related Tutorials