线程卡死玩家无法进入游戏

zhangshanxue 2020-05-16 16:08:26 +08:00
parent 1d28d4e51d
commit c4471cb7f9
1 changed files with 6 additions and 0 deletions

View File

@ -174,9 +174,15 @@ public class MathUtils {
* @return
*/
public static List<Integer> randomForOneArray(int sourceArray[], int randomNums) {
List<Integer> result = new ArrayList<>();
if(randomNums==0){
return result;
}
int length = sourceArray.length;
Set<Integer> cacheIndexs = new HashSet<>();
// 这种while循环我觉得还是尽量避免下 或者一定要有个循环上限
while (randomNums>0){
int randomPos = randomInt(length);
if(cacheIndexs.contains(randomPos)){