Random number generator

I dont really get what it is asking me to do.
"Type a statement using srand() to seed random number generation using variable seedVal. Then type two statements using rand() to print two random integers between 0 and 9. End with a newline"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <cstdlib>   // Enables use of rand()
#include <ctime>     // Enables use of time()
using namespace std;

int main() {
   int seedVal = 0;

 
seedVal=time(0); 
srand(seedVal); 

cout << (rand() % 10) << endl;
cout << (rand() % 10) << endl;

   return 0;
}
Last edited on
1
2
cout << (rand() % 10) << endl;
cout << (rand() % 10) << endl;


Should be :
cout << (rand() % 10) << (rand() % 10) << endl;
Here’s a sample program using these functions:

#include <iostream>
#include <cstdlib> // for rand() and srand()

int main()
{
srand(5323); // set initial seed value to 5323

// Print 100 random numbers
for (int count=0; count < 100; ++count)
{
std::cout << rand() << "\t";

// If we've printed 5 numbers, start a new row
if ((count+1) % 5 == 0)
std::cout << "\n";
}
}
No, that didnt work for me either.
I don't really get what it is asking me to do.

What are you trying to say?
Sorry let me clarify. I meant i dont know what to do to do what they are asking.
I think your original code already does what it's supposed to do.
Topic archived. No new replies allowed.