向一個數組中拔出一個1~100的隨機數。本站提示廣大學習愛好者:(向一個數組中拔出一個1~100的隨機數)文章只能為提供參考,不一定能成為您想要的結果。以下是向一個數組中拔出一個1~100的隨機數正文
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int>();
Random ran = new Random();
while(true)
{
if (list.Count >= 100)
{
break;
}
int s = ran.Next(1, 101);
if (!list.Contains(s))
{
list.Add(s);
}
}
list.Sort();
foreach (int i in list)
{
Console.Write(i + " ");
}
Console.ReadKey();
}
}
}