# questions....so many questions about random numbers....

• 08-26-2001
face_master
questions....so many questions about random numbers....
As you can tell by the title, I ask too many questions about random numbers...and they arn't even very useful!

Well, I hope this will be the last one about random numbers and here it goes (oh yeah, and by the way, I bet stoned_coder will answer this one. He answers all my questions!! THANKS!!)...

To display a random number, you do this...

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int main()
{
srand(time(NULL));
cout <<"A random number from 0 to 99: "<< rand() % 100;

return 0;
}

...but what i'd like to know is how would you store the random number into an int type variable (or any type of variable, for that matter) such as int nrandom; ??

Thanks
-Chris
• 07-30-2009
cmay
Quote:

Originally Posted by face_master
As you can tell by the title, I ask too many questions about random numbers...and they arn't even very useful!

Well, I hope this will be the last one about random numbers and here it goes (oh yeah, and by the way, I bet stoned_coder will answer this one. He answers all my questions!! THANKS!!)...

To display a random number, you do this...

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int main()
{
srand(time(NULL));
cout <<"A random number from 0 to 99: "<< rand() % 100;

return 0;
}

...but what i'd like to know is how would you store the random number into an int type variable (or any type of variable, for that matter) such as int nrandom; ??

Thanks
-Chris

you could try something like this.
its been very long since i touched c++ so i hope its correct.
Code:

```#include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() {         int  random_array[10];         int i;         srand(time(NULL)); cout <<"A random number from 0 to 99: "<< rand() % 100; // fill the random array wiht random numbers for(i=0;i < 10;i++)   random_array[i]=rand() % 100;  // print the random numbers to screen  for(i=0;i < 10;i++)   cout <<"random array number"<<random_array[i]<<"\n";  return 0; }```
• 07-30-2009
Salem
Couldn't you find a thread OLDER THAN 2001 to bump?