Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you please help me with this problem by using C++ Here is a randint function

ID: 3806052 • Letter: C

Question

Can you please help me with this problem by using C++

Here is a randint function to use:

//randint.cpp

#include "randint.h"

#include <chrono>

using namespace std::chrono;

//linear congruential pseudorandom number generator

int randint(){

         //use the clock for an initial pseudorandom number

         static long x = time_point_cast<microseconds>(system_clock::now())

                                     .time_since_epoch().count();

         //calculate the next pseudorandom number

         //parameters from glibc(?)

         x = long(long(1103515245 * x) + 12345)) & 0x7fffffff;   

         return x;

}

You do not have to understand this function for now (but feel free to figure

out or look up as much as you wish!); just call it to get a "random" number.

Put this code in a file named randint.cpp, and also write the matching header

file randint.h. Write a main named hw4pr1.cpp which calls randint 1000000 times and counts how many times the last digit (in decimal) is a 0, a 1, etc. The

output might look like this:

There were 99875 0's.

There were 103248 1's.

There were 90802 2's.

and so on. If randint is really pretty random, all the counts will be close to

100000, or the counts might be all over the place if it is not very random.

Explanation / Answer

Find th code for main as below.

#include <iostream>

using namespace std;

int main()
{
   long i,x,ctr[10]={0};
   int lst;
   for (i=0; i<1000000; i++)
   {
       x = randint();
       lst = x%10;
       ctr[lst]++;

   }
   for(i=0; i<10; i++)
       cout<<"There were "<<ctr[i]<<" "<<i<<"'s"<<endl;
return 0;
}