Page 1 of 1

how to order a new list?

Posted: Mon Dec 12, 2011 1:12 pm
by Juan Carlos
I have this big doubt because I don't remember as do it, I want sorting a list of random numbers proving that these numbers are not repeated, for example I want make a cards game but I want sort the 52 cards or numbers without they are repeat but using the random system, I remember the bubble method, but after of several years without programming much things I forget.

Re: how to order a new list?

Posted: Mon Dec 12, 2011 5:37 pm
by jalih
Hello,

If I understood your problem correctly, something like this should work:

Code: Select all

; Holds the card deck in number order
Local deck = {}
For Local i = 0 To 51
	deck[i] = i
Next

; Build the shuffled game card deck
Local game_deck = {}
For Local i = 51 To 0 Step -1
	Local k = Rnd(i+1)
	InsertItem(game_deck, deck[k])
	RemoveItem(deck, k)
Next

; Print contents of the game deck to show it worked
For Local i = 0 To 51
	DebugPrint(game_deck[i])
Next

Re: how to order a new list?

Posted: Tue Dec 13, 2011 9:12 pm
by Juan Carlos
Thank you jalih, for your help and explanations, I'll text it, and when I finish my game, I can give you the thanks publicly in my game?
Because I forgot in other project mine, sorry.