Can someone help me understand why the randRange function below doesn't
return a random distribution, but the randRange2 function does?
Here's some test code.

thanks, - rajat


var a = [0,0,0,0,0];
var b = [0,0,0,0,0];
var x;

for (var i=0; i < 1000; i++) {
   x = randRange(1,4);
   a[x]++;
   x = randRange2(1,4);
   b[x]++;

}

trace ("a: " + a);
trace ("b: " + b);


// ----------------------------------------------
// Generate a random number in a range.
function randRange(min, max) {
 var randomNum = Math.round(Math.random()*(max-min))+min;
 return randomNum;
}

// Generate a random number in a range.
function randRange2(min, max) {
 var randomNum = min + Math.floor(Math.random() * (max + 1 - min));
 return randomNum;
}

--
Rajat Paharia
[EMAIL PROTECTED]
http://www.bunchball.com
http://www.rootburn.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to