java - Trying to shuffle a "Deck" class, doesn't seem to be shuffling -
i've written deck class , have shuffle it, , print out few hands check how works. however, doesn't seem shuffle anything, rather give exact same deck.
public void makehands () { deck deck = new deck (); deck shuffled = shuffledeck (deck); printdeck (subdeck (shuffled, 0, 4)); printdeck (subdeck (shuffled, 5, 9)); printdeck (subdeck (shuffled, 10, 14)); printdeck (subdeck (shuffled, 15, 19)); } public static int randomint (int length, int i) { double x = math.random () * length; int g = (int) x; return g; } public deck shuffledeck (deck deck) { (int i=0; i<deck.cards.length; i++) { int g = randomint (deck.cards.length, i); swapcards (i, g); } return deck; } } public void swapcards (int first, int swap) { card temp = cards[first]; cards[first] = cards[swap]; cards[swap] = temp; }
the code looks incomplete.
it looks need pass deck object swapcards method.
swapcards() referring cards array. n't clear array declared. instead should pass deck method , swap deck.cards[first] , deck.cards[swap].
Comments
Post a Comment