我只是偶然發現了一個很簡單的問題。假設你有分配給學生的整數值(例如時間段)。每個學生都會發送時間分配請求,並隨機給出一個。時隙分配 - 設計和方法
我想acieving的以下列:
List<Integer> possibleSlots;
Map<Integer, Student> allocatedSlots;
現在爲每個請求我會做某事,如:
Random r = new Random();
int slot = possibleSlots.removeAt(r.next(possibleSlots.size()));
allocatedSlots.put(slot, student);
請問下面的方法是某事適合作爲一般的場景隨機分配插槽,並且在沒有使用可能的插槽列表的情況下保存誰有哪個插槽或有沒有更好的方法?