Skip to content

Commit

Permalink
update shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
aprilywy committed Jan 21, 2024
1 parent ad88df6 commit 5e710e5
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package tw.waterballsa.gaas.citadels.spring.util;

import java.util.List;
import java.util.Random;

public class CitadelsUtils {
static void shuffle(Object[] List, int cards) {
public class CitadelsUtils<T> {

public static <T> void shuffle(List<T> cards) {
Random rd = new Random();

for (int i = cards - 1; i > 0; i--) {
int j = rd.nextInt(i+1);
for (int i = cards.size() - 1; i > 0; i--) {
int j = rd.nextInt(i + 1);

Object temp = List[i];
List[i] = List[j];
List[j] = temp;
T temp = cards.get(i);
cards.set(i, cards.get(j));
cards.set(j,temp);
}
}
}
Expand Down

0 comments on commit 5e710e5

Please sign in to comment.