Posted By

dandyna on 07/24/06


Tagged

javascript random


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

dandyna
marza
nutella


Random number, without sequencial duplicates


 / Published in: JavaScript
 

URL: http://dandyland.org

function prints a serie of random numbers but without the next one being the same as the previous. to print, just call the function in the body

  1. <script type='text/javascript'>
  2. randomNum = 0;
  3. function noDuplicate(maxNum)
  4. {
  5. current = randomNum;
  6. while (current == randomNum) {
  7. current = Math.round(Math.random()*maxNum);
  8. }
  9. randomNum = current;
  10. return current;
  11. }
  12. </script>

Report this snippet  

You need to login to post a comment.