I've got my random number generator created and functioning, but I need it to not repeat any numbers as it runs. How do I do that? Thanks for the help.
lavazza
3:24 am on Nov 21, 2009 (gmt 0)
If you control the output, then - by definition - your generator will be non-random
j2trumpet
4:34 am on Nov 21, 2009 (gmt 0)
Thanks for the advice, but that doesn't answer my question.
Can anyone else help me?
daveVk
5:45 am on Nov 21, 2009 (gmt 0)
Store the 'used' answers. If you get a used answer try again.
j2trumpet
5:59 am on Nov 21, 2009 (gmt 0)
How do I do that?
daveVk
6:48 am on Nov 21, 2009 (gmt 0)
var used = []; ... function getUniq(){ var n; while ( used[ n = getRand() ] ){} used[ n ] = true; return n; }
replace getRand() with your get random code
rocknbil
5:09 pm on Nov 21, 2009 (gmt 0)
Another way would be to splice/remove the element from the random array until it's length is zero. When it reaches zero length, repopulate it.