Posted By

marcio on 01/25/10


Tagged

javascript numbers random


Versions (?)

Random numbers


 / Published in: JavaScript
 

  1. // Returns a random number between min and max
  2. function getRandom(min, max)
  3. {
  4. return Math.random() * (max - min) + min;
  5. }
  6.  
  7. // Returns a random integer between min and max
  8. // Using Math.round() will give you a non-uniform distribution!
  9. function getRandomInt(min, max)
  10. {
  11. return Math.floor(Math.random() * (max - min + 1)) + min;
  12. }

Report this snippet  

You need to login to post a comment.