生成一个随机数

生成一个1  ——100 的随机整数

下面是用C#控制台写的一个例子:

 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             int[] intArr = new int[100];
 6             ArrayList myList = new ArrayList();
 7             Random rnd = new Random();
 8 
 9             while (myList.Count < 100)
10             {
11                 int num = rnd.Next(1, 101);//随机数的范围1 - 100
12                 if (!myList.Contains(num)) myList.Add(num);
13             }
14 
15             for (int i = 0; i < 100; i++)
16             {
17                 intArr[i] = (int)myList[i];
18                 Console.Write(" " + intArr[i]);//遍历输出随机数
19             }
20 
21             Console.ReadKey();
22         }
23 
24     }
原文地址:https://www.cnblogs.com/dt520/p/5711433.html