生成随机数1-100

gx1*_*x15 2 c# random average max min

我需要生成从1到100的随机数,我知道如何做这个部分......

我需要询问用户他想要生成多少个数字(如果他说5该程序需要从1到100生成5个数字).我现在只知道如何通过在列表中添加新的int来创建可修复的金额.

我之前做过那个,但后来我无法使它工作,所以它会写出这些数字的平均值和最小值+最大值.

这是我的代码如下:

Random k = new Random(); 
//here i added in the same way other variables and put them in a list
int j = k.Next(100);

Console.WriteLine("");
double[] list1 = {j}; 
double povp = list1.Average();
Console.WriteLine(povp);

Console.WriteLine("");
Console.WriteLine(list1.Max()); 
Console.WriteLine("");
Console.WriteLine(list1.Min());

Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)

aqu*_*aga 5

您可以使用以下代码生成N个数字:

IEnumerable<int> numbers = Enumerable.Repeat(1,N).Select(_ => random.Next(100));
Run Code Online (Sandbox Code Playgroud)