Hello
I'm trying to randomly generate the hands of two players for the initial deal of a card game.
Im using ArrayLists player1Deck and player2Deck to cut 52 cards in half , but I can't seem to figure out how to get rid of the duplicates floating around in each player's deck.
Any tips to point me in the right direction would be great.
Thanks
I'm trying to randomly generate the hands of two players for the initial deal of a card game.
Im using ArrayLists player1Deck and player2Deck to cut 52 cards in half , but I can't seem to figure out how to get rid of the duplicates floating around in each player's deck.
Any tips to point me in the right direction would be great.
Thanks
public void initialDeal() {
while ( player1Deck.size() < 26 ) {
// random number between 0 and 51
int randomNum = (int)(Math.random() * 51);
if ( !player1Deck.contains (randomNum ))
{
player1Deck.add ( randomNum ) ;
}
}
while ( player2Deck.size () < 26 ) {
int randomNum = ( int ) ( Math.random () * 51 ) ;
if ( !player2Deck.contains ( randomNum ))
{
player2Deck.add ( randomNum ) ;
}
}
}