/**
* 生成m个不重复随机数组
* @param limit 若为10 则产生 0~9之间的随机数
* @param need m个
* @return 随机数组
*/
private static int[] getRandomMethod(int limit, int need)
{
int[] tempArray = new int[limit];
int[] resArray = new int[need];
for (int i = 0; i < limit; i++)
{
tempArray[i] = i;
}
int w = 0;
Random rand = new Random();
for (int i = 0; i < need; i++)
{
w = rand.nextInt(limit - i) + i;
int t = tempArray[i];
tempArray[i] = tempArray[w];
tempArray[w] = t;
resArray[i] = tempArray[i];
}
return resArray;
}
* 生成m个不重复随机数组
* @param limit 若为10 则产生 0~9之间的随机数
* @param need m个
* @return 随机数组
*/
private static int[] getRandomMethod(int limit, int need)
{
int[] tempArray = new int[limit];
int[] resArray = new int[need];
for (int i = 0; i < limit; i++)
{
tempArray[i] = i;
}
int w = 0;
Random rand = new Random();
for (int i = 0; i < need; i++)
{
w = rand.nextInt(limit - i) + i;
int t = tempArray[i];
tempArray[i] = tempArray[w];
tempArray[w] = t;
resArray[i] = tempArray[i];
}
return resArray;
}