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.
Asked
Active
Viewed 1.3e+01k times
46
-
6Can you show us the code that you have tried? – Adriaan Stander Jul 31 '13 at 04:37
-
Sounds like you should read up on http://msdn.microsoft.com/en-us/library/ch45axte.aspx and http://msdn.microsoft.com/en-us/library/system.random.aspx – chancea Jul 31 '13 at 04:40
-
See this: https://stackoverflow.com/questions/2706500/how-do-i-generate-a-random-int-number – Henrik Høyer Jul 21 '21 at 08:46
2 Answers
96
Have you tried this
Random integer between 0 and 1000(1000 not included):
Random random = new Random();
int randomNumber = random.Next(0, 1000);
Loop it as many times you want

Rohit
- 10,056
- 7
- 50
- 82
5
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.

Gordon Mackie JoanMiro
- 3,499
- 3
- 34
- 42

Manish Sharma
- 2,406
- 2
- 16
- 31
-
9If you run this multiple times in succession you would likely end up with the same random number! – Joe Shanahan Dec 14 '13 at 18:16
-
6I would think you would want to pass min and max values to the Next method. Then call RandomNumber, like so: RandomNumber(1, 1000) – puddinman13 Apr 06 '15 at 17:04