Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. package poker.table;
  2.  
  3. import java.security.SecureRandom;
  4.  
  5. public class CardShuffler {
  6. private int[] cards = new int[52];
  7.  
  8. public int[] shuffle() {
  9. this.rearrangeCards();
  10. SecureRandom secureRandom = new SecureRandom();
  11.  
  12. for (int i = 0; i < this.cards.length; i++) {
  13. int randomPosition = i + secureRandom.nextInt(this.cards.length - i);
  14. int temp = this.cards[i];
  15. this.cards[i] = this.cards[randomPosition];
  16. this.cards[randomPosition] = temp;
  17. }
  18.  
  19. return this.cards;
  20. }
  21.  
  22. private void rearrangeCards() {
  23. for(int i = 0; i < this.cards.length; this.cards[i] = i++) {
  24. this.cards[i] = i;
  25. }
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement