Results 1 to 2 of 2

Thread: HELP: random (non repeating) number gen

                  
   
  1. #1
    DCEmu Newbie
    Join Date
    Oct 2005
    Posts
    1
    Rep Power
    0

    Default HELP: random (non repeating) number gen

    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

  2. #2
    DCEmu Newbie
    Join Date
    Oct 2005
    Posts
    12
    Rep Power
    0

    Default

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •