# Random Number!

This is a discussion on Random Number! within the C++ Programming forums, part of the General Programming Boards category; Hey, In a Windows Console Application, how do i output a random number out of certain numbers (e.g. 1 to ...

1. ## Random Number!

Hey,

In a Windows Console Application, how do i output a random number out of certain numbers (e.g. 1 to 50) And if i want to output another say 5 random numbers how do i make it so the numbers are not the same as the ones outputed earlier??

So if i wanted to output 5 random numbers, between 1 and 50, and i do not want then to be the same, how do i do it?? is there a function in the standard C++ library for it??

P.S. I use Microsoft Visual C++ 6

2. and let me tell you one mor thing there is no way of generating a true random number from your computer.... The computer uses some algorithm which mimics the generation of true randomness... TO get a true random number you need to get input from your sorroundings such as sound etc etc

3. >there is no way of generating a true random number from your computer

Not true. How much would you like to bet me that you're mistaken?

4. Originally posted by Davros
Not true. How much would you like to bet me that you're mistaken?
There are PCI-cards that generate random numbers using radioactive isotopes.
But it is impossible to generate true random numbers using only software. Very good random numbers can be generated.

5. >There are PCI-cards that generate random numbers using radioactive isotopes.

I was waiting Vasanth to bite on that!

6. To generate five numbers between 1 - 50 you can use this:
for ( int i=0; i<8; i++ )
{
cout << 1+rand()%50 << endl;
}

Don't forget to include <cstdlib> and if you want to radomize the number generation use the fucntion srand().

You can use this srand(time(0)), so you the numbers keep changing according to the time the program is being executed.

Note: To use the function time() you should include <ctime>.