<summary>
Random ra=new random (); The system automatically selects the current time before making a random seed:
Random ra=new Random (6) specifies a parameter of type int as a stochastic seed;
Ra. Next (); Returns a random number greater than or equal to zero and less than 2,147,483,647
Ra. Next (20); Returns a random number that is greater than or equal to zero and less than 20
Ra. Next (1,20); Returns a random number greater than or equal to 1 and less than 20
The following function returns a positive integer that is greater than or equal to a positive integer (with 0) and less than or equal to a positive whole number.
Example int[] a= getrandomnum (12,1,100); Randomly pick 12 different numbers in 1-100 to coexist in array a
Come from one place.
</summary>
Public int[] getrandomnum (int num, int minValue, int maxValue)
{
if ((MaxValue + 1-minvalue-num<0))
MaxValue + = num-(maxValue + 1-minvalue);
Random RA = new Random (unchecked ((int) DateTime.Now.Ticks));
int[] Arrnum = new Int[num];
int tmp = 0;
StringBuilder sb=new StringBuilder (num *maxvalue. ToString (). Trim (). Length);
for (int i = 0; I <= num-1; i++)
{
TMP = RA. Next (MinValue, MaxValue);
while (SB.) ToString (). Contains ("#" + tmp.) ToString (). Trim () + "#")
TMP = RA. Next (MinValue, maxvalue+1);
Arrnum[i] = tmp;
Sb. Append ("#" + tmp.) ToString (). Trim () + "#");
}
return arrnum;
}
C # randomly generates several distinct random numbers within a range of numbers