From ad88df6a70367edafd3eaebe3315842f9b4c4b80 Mon Sep 17 00:00:00 2001 From: aprilywy Date: Fri, 8 Dec 2023 22:31:49 +0800 Subject: [PATCH] update CitadelsUtils --- .../citadels/spring/util/CitadelsUtils.java | 18 ++++++++++++ .../gaas/citadels/spring/util/shuffle.java | 28 ------------------- 2 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/CitadelsUtils.java delete mode 100644 packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/shuffle.java diff --git a/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/CitadelsUtils.java b/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/CitadelsUtils.java new file mode 100644 index 00000000..2ba24e5a --- /dev/null +++ b/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/CitadelsUtils.java @@ -0,0 +1,18 @@ +package tw.waterballsa.gaas.citadels.spring.util; + +import java.util.Random; + +public class CitadelsUtils { + static void shuffle(Object[] List, int cards) { + Random rd = new Random(); + + for (int i = cards - 1; i > 0; i--) { + int j = rd.nextInt(i+1); + + Object temp = List[i]; + List[i] = List[j]; + List[j] = temp; + } + } +} + diff --git a/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/shuffle.java b/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/shuffle.java deleted file mode 100644 index eceacade..00000000 --- a/packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/util/shuffle.java +++ /dev/null @@ -1,28 +0,0 @@ -package tw.waterballsa.gaas.citadels.spring.util; - -import java.util.Arrays; -import java.util.Random; - -public class shuffle { - static void shuffle(int array[], int a) { - Random rd = new Random(); - - for (int i = a - 1; i > 0; i--) { - int j = rd.nextInt(i+1); - - int temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - - System.out.println(Arrays.toString(array)); - } - - public static void main(String[] args) { - int[] ar = {1,2,3,4,5}; - - int b = ar.length; - shuffle(ar, b); - } -} -