Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[JAVAscript]Math.random()?

Elite Diviner
Joined
Jul 15, 2005
Messages
404
Reaction score
2
How effective is this fomula in getting
1(inclusive) to 100(inclusive) value at random?

Math.floor((Math.random()+0.01) * 100);

Any suggestion for better one?


Say, my math.random() gets 0.9999
I +0.01 it, and it gives 1.0999
then times 100, i get 100.99, after I math.floor it, it is 100 right? not 110.
 
Last edited:
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
Code:
function nrand(min,max){
  return Math.round(Math.random()*(max-min))+min;
}

Enjoy. This isn't uniform for values min and max, though.

This is:

Code:
function unrand(min,max){
  var n = min-1;
  while(n != min-1 && n != max+1) n = nrand(min-1,max+1);
  return n;
}
 
Last edited:
Elite Diviner
Joined
Jul 15, 2005
Messages
404
Reaction score
2
Sorry for coming back late. will test this out now
 
Back
Top