循环,生成20-50范围内的10个随机数并显示它

时间:2016-03-14 20:40:34

标签: c#

class MainClass
{
    public static void Main (string[] args)
    {
        // Question #3 answer

        int number;
        int min=20,max=50;
        Random RandomNumber = new Random();

        for ( number= 20; number<=50; number++)

            RandomNumber.Next(20, 50);

        Console.WriteLine (number);                                                                 
    }    
}

1 个答案:

答案 0 :(得分:-1)

你想:

    int min=20,max=50;
    Random RandomNumber = new Random();

    for (var count = 0; count<10; count++)
        Console.WriteLine(RandomNumber.Next(min, max));

for循环运行10次迭代,每次迭代Console.WriteLine()都是minmax之间的新随机数。