一、Random
Random random = new Random(); //放循环体外初始化 for (int i = 0; i <= 9; i++) { int temp = random.Next(1, 100); Console.WriteLine(temp ); }
注意将初始化random放在循环体外边
Random.Next(min, max)随机返回一个整数a,其中a大于等于min,小于max。
API:https://docs.microsoft.com/zh-cn/dotnet/api/system.random.next?redirectedfrom=MSDN&view=netframework-4.7.2#System_Random_Next_System_Int32_System_Int32_