how to order a new list?
- Juan Carlos
- Posts: 933
- Joined: Mon Sep 06, 2010 1:02 pm
how to order a new list?
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?
Hello,
If I understood your problem correctly, something like this should work:
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
- Juan Carlos
- Posts: 933
- Joined: Mon Sep 06, 2010 1:02 pm
Re: how to order a new list?
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.
Because I forgot in other project mine, sorry.