PDA

View Full Version : HELP: random (non repeating) number gen



ev0lution
October 7th, 2005, 02:04
function shuffle()
while counter1 <=52 do
rancardnum=math.random(52) --get random #
if checkifused()==0 then --check if alerady exsists
rawset(numberholder, counter1, rancardnum) --add to array
end
end
end

function checkifused()

while counter2 <=52 do
used=rawget numberholder[counter2] --get placeholder #
counter2 = counter2 +1 --increment counter2
if used=rancardnum itsused = 1 --if number exsists break
if itsused==1 then return 1 --returns 1 if exsists

end

end

skyd1v3r
October 29th, 2005, 06:06
you forgot to increase counter1.

function shuffle()
while counter1 <=52 do
rancardnum=math.random(52) --get random #
if checkifused()==0 then --check if alerady exsists
rawset(numberholder, counter1, rancardnum) --add to array
end
counter1 = counter1+1 -- THIS HERE!
end
end