[英]How to randomize an array of a String so it is different every time though the loop
[英]How to randomize the entries in a List so the user sees a different DailyPrayer each time?
我有一个方法可以对某些元素进行查找,并将其返回给用户:
List<DailyPrayer> dailyPrayers = (List<DailyPrayer>) query.execute();
return dailyPrayers;
这些是日常祈祷,因此我希望用户每次都能看到不同的祈祷,以免他们一遍又一遍地看到相同内容而感到无聊。
如何将列表随机化?
使用默认的随机性源随机排列指定的列表。 所有排列发生的可能性几乎相等。
shuffle(List<?> list)
Randomly permutes the specified list using a default source of randomness.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.