c#中0-1000之间的随机数生成器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17961700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:56:31  来源:igfitidea点击:

random number generator between 0 - 1000 in c#

c#randomnumbers

提问by user2636592

I need help in writing a program that will generate 100 random numbers between 0 and 1000. The out put needs to be displayed in a windows message box. i'm stuck as to what code I have use to get the numbers in the box and to only have 100 random numbers.

我需要帮助编写一个程序,该程序将生成 0 到 1000 之间的 100 个随机数。输出需要显示在 Windows 消息框中。我不知道我使用什么代码来获取框中的数字并且只有 100 个随机数。

回答by Rohit

Have you tried this

你有没有试过这个

Random integer between 0 and 1000(1000 not included):

0 到 1000 之间的随机整数(不包括 1000):

Random random = new Random();
int randomNumber = random.Next(0, 1000);

Loop it as many times you want

循环多次

回答by Manish Sharma

Use this:

用这个:

static int RandomNumber(int min, int max)
{
    Random random = new Random(); return random.Next(min, max);

}

This is example for you to modify and use in your application.

这是您在应用程序中修改和使用的示例。