46

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.

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
user2636592
  • 517
  • 1
  • 4
  • 5

2 Answers2

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
  • 9
    If 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
  • 6
    I 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