Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package poker.table;
- import java.security.SecureRandom;
- public class CardShuffler {
- private int[] cards = new int[52];
- public int[] shuffle() {
- this.rearrangeCards();
- SecureRandom secureRandom = new SecureRandom();
- for (int i = 0; i < this.cards.length; i++) {
- int randomPosition = i + secureRandom.nextInt(this.cards.length - i);
- int temp = this.cards[i];
- this.cards[i] = this.cards[randomPosition];
- this.cards[randomPosition] = temp;
- }
- return this.cards;
- }
- private void rearrangeCards() {
- for(int i = 0; i < this.cards.length; this.cards[i] = i++) {
- this.cards[i] = i;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement