asp.Net重複乱数コードなし
994 ワード
///
///
///
///
///
///
///
public int[] getNum(int num, int minValue, int maxValue)
{
Random ra = new Random(unchecked((int)DateTime.Now.Ticks));
int[] arrNum = new int[num];// : 0, 0
int tmp = 0;
for (int i = 0; i < num; i++)
{
tmp = getRandomNum(tmp, minValue, maxValue, ra);//
if (Array.IndexOf(arrNum, tmp) < 0)// , tmp -1
{
arrNum[i] = tmp;
}
else
{
i = i - 1;
}
}
return arrNum;
}
public int getRandomNum(int tmp, int minValue, int maxValue, Random ra)
{
tmp = ra.Next(minValue, maxValue);
return tmp;
}