Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

random number generator between 0 - 1000 in c# [closed]

Tags:

c#

random

numbers

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.

like image 866
user2636592 Avatar asked Jul 31 '13 04:07

user2636592


People also ask

How do you generate a random number between 0 and 100 in C++?

Thus using the two functions, rand () and srand () we can generate random numbers in C++. The function srand () is used to provide seed for generating random numbers while rand () function generates the next random number in the sequence.

How do you generate a random number from 0 to 99 in C++?

rand()– To generate the numbers from 0 to RAND_MAX-1 we will use this function. Here RAND_MAX signifies the maximum possible range of the number. Let's say we need to generate random numbers in the range, 0 to 99, then the value of RAND_MAX will be 100.


2 Answers

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

like image 114
Rohit Avatar answered Oct 04 '22 06:10

Rohit


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.

like image 20
Manish Sharma Avatar answered Oct 04 '22 07:10

Manish Sharma