Merge branch 'master' of http://60.1.1.230/backend/jieling_server
commit
b4f77dd3c3
|
@ -4,9 +4,7 @@ import com.sun.nio.sctp.PeerAddressChangeNotification;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
|
||||
|
@ -172,11 +170,23 @@ public class MathUtils {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数组索引就行随机
|
||||
* @param sourceArray
|
||||
* @param randomNums
|
||||
* @return
|
||||
*/
|
||||
public static List<Integer> randomForOneArray(int sourceArray[], int randomNums) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
int length = sourceArray.length;
|
||||
Set<Integer> cacheIndexs = new HashSet<>();
|
||||
while (randomNums>0){
|
||||
result.add(sourceArray[randomInt(length)]);
|
||||
int randomPos = randomInt(length);
|
||||
if(cacheIndexs.contains(randomPos)){
|
||||
continue;
|
||||
}
|
||||
cacheIndexs.add(randomPos);
|
||||
result.add(sourceArray[randomPos]);
|
||||
randomNums--;
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue