Ask Question

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. Ex:

5

7

Note: For this activity, using one statement may yield different output (due to the compiler calling rand () in a different order). Use two statements for this activ

+4
Answers (1)
  1. 17 June, 00:18
    0
    The C+ + code is given below with appropriate comments

    Explanation:

    //Use stdafx. h for visual studio.

    #include "stdafx. h"

    #include

    //Enable use of rand ()

    #include

    //Enable use of time ()

    #include

    using namespace std;

    int main ()

    {

    //Note that same variable cannot be defined to two

    //different type in c++

    //Thus, use either one of the two statement

    //int seedVal=0; time_t seedVal;

    //int seedVal=0;

    time_t seedVal;

    seedVal = time (0);

    srand (seedVal);

    //Use rand to generate two number by setting range

    / / between 0 and 9. Use endl for newline.

    cout << (0 + rand () % ((10 - 0) + 0)) << endl;

    cout << (0 + rand () % ((10 - 0) + 0)) << endl;

    //Use for visual studio.

    system ("pause");

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Type a statement using srand () to seed random number generation using variable seedVal. Then type two statements using rand () to print ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers