陈士柏 2 лет назад
Родитель
Сommit
ca64580f79
1 измененных файлов с 24 добавлено и 0 удалено
  1. 24 0
      mhotel/src/com/happy/Until/RandomSelection.java

+ 24 - 0
mhotel/src/com/happy/Until/RandomSelection.java

@@ -0,0 +1,24 @@
+package com.happy.Until;
+
+import com.happy.Model.Hotel;
+import org.apache.poi.ss.formula.functions.T;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class RandomSelection {
+
+    public static List<Hotel> getList(List<Hotel> list, int numberOfElementsToSelect){
+        List<Hotel> selectedElements = new ArrayList<>();
+        Random random = new Random();
+
+        for (int i = 0; i < numberOfElementsToSelect; i++) {
+            int randomIndex = random.nextInt(list.size());
+            selectedElements.add(list.get(randomIndex));
+            list.remove(randomIndex);
+        }
+        return selectedElements;
+    }
+
+}