how to order a new list?

Find quick help here to get you started with Hollywood
Post Reply
User avatar
Juan Carlos
Posts: 933
Joined: Mon Sep 06, 2010 1:02 pm

how to order a new list?

Post 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.
jalih
Posts: 281
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: how to order a new list?

Post 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
User avatar
Juan Carlos
Posts: 933
Joined: Mon Sep 06, 2010 1:02 pm

Re: how to order a new list?

Post 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.
Post Reply