| 1234567891011121314151617181920212223242526272829303132 |
- package com.goafanti.common.utils;
- import java.util.Random;
- public class RandomUtil {
- public static int[] generateRandomList(int maxNum, int count) {
- int[] res = new int[count];
- Random rand = new Random();
- boolean flag = false;
- int randInt = 0;
- for (int i = 0; i < count; i++) {
- do {
- randInt = rand.nextInt(maxNum);
- for (int i1 = 0; i1 < count; i1++) {
- if (res[i1] == randInt) {
- flag = false;
- break;
- }
- flag=true;
- }
- } while (!flag);
- flag = false;
- res[i] = randInt;
- }
- return res;
- }
-
- }
|