Question: Need help adjusting this code in C. I'm not sure this one part of the code is correct, it needs to generate n random addresses
Need help adjusting this code in C. I'm not sure this one part of the code is correct, it needs to generate n random addresses between 0 and (2^32)-1. So I set it to "address = rand() % 232;" but I'm not sure if that is correct. Can you please fix thanks.
#include
int main() {
unsigned int address; unsigned int pg_num; unsigned int offset; unsigned int i; unsigned int n = 1000000; double time_taken;
srand((unsigned)time(NULL)); clock_t begin = clock();
for (i = 0; i < n; i++) { address = rand() % 232; pg_num = address / 4096; offset = address % 4096; }
clock_t end = clock();
time_taken = (double)(end - begin) / CLOCKS_PER_SEC; printf("Total CPU time: %f ", time_taken); return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
