Array Random Sorting

Status
You're currently viewing only Thanatos's posts. Click here to go back to viewing the entire thread.
Not open for further replies.
I used a 2D array of booleans tracking which cards had been dealt. Then I ran a loop:

while(true)
{
Randomly choose a suit and face value
If it hasn't been dealt already, mark it as dealt and return a card with those characteristics
}

EDIT: The above was the deck's "deal card" method. To reshuffle the deck, merely reinitialize the array of booleans.
 
Big O analysis of finding that 52nd card?
Completely random. It might pick it first, or pick a million other cards first. In actual use, however, the loop ran instantly (in Java) when asked to produce 52 different cards.

If the algorithm needed to be scalable, I probably wouldn't do it that way. With only 52 cards, however, it just wasn't a problem.
 
Status
You're currently viewing only Thanatos's posts. Click here to go back to viewing the entire thread.
Not open for further replies.