Copy Code code as follows:
<summary>
Produce no repeat random number
</summary>
<param name= "num" > Number </param>
<param name= of "MinValue" > Min </param>
<param name= of "MaxValue" > Max </param>
<returns> Array </returns>
Public int[] getnum (int num, int minvalue, int maxValue)
{
Random ra = new Random (unchecked (int) DateTime.Now.Ticks));
int[] Arrnum = new int[num];//Note: The initial value of the elements in the array is 0, and when 0 is in the range of values, it is handled separately
int tmp = 0;
for (int i = 0; i < num; i++)
{
TMP = Getrandomnum (tmp, MinValue, MaxValue, RA),//Fetch value assigned to array
if (Array.indexof (Arrnum, TMP) < 0)//To determine whether or not to exist, the index of element tmp should be-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;
}