Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The programming language has to be C. Do you remember rand()? Do you remember how it can use srand() for a seed? Did you know

The programming language has to be C.

Do you remember rand()? Do you remember how it can use srand() for a seed? Did you know that rand uses that seed as the initial state of their random number generator. Did you know that a random number generator is really a deterministic sequence generator?

Yeah! So your next random number might be calculated using a recursive equation like:

rand_n = rand_(n-1) * coeffecient1 + coeffecient2

That is the random number produced is the previous random number times coeffecient1 plus coeffecient2.

Random number generators rely on unsigned integer overflow.

For this question, question2.c has already been started. Don't change the lines above // Don't change anything above this line or below // Don't change anything below this line.

Replace // Your code goes here with your code.

Based on what's already in question2.c provide the functions seedMyRand and myRand. Code in question2.c that has been already started:

#include #include #include #include

#define DEFAULT_SEED 1 #define DEFAULT_COEFFECIENT1 1234567891 #define DEFAULT_COEFFECIENT2 987654321 const uint64_t MODULUS_CONSTANT = 10; const uint64_t DEFAULT_NUMBERS = 1;

uint64_t coeffecient1 = DEFAULT_COEFFECIENT1; uint64_t coeffecient2 = DEFAULT_COEFFECIENT2;

// Don't change anything above this line

// Your code goes here

// Don't change anything below this line

uint64_t input_u64(uint64_t default_value) { /* Read a u64 from the input, (user or file) * using default_value instead if the user enters 0 */ uint64_t input_value = 0; int scanned = scanf("%llu", (long long unsigned int *) &input_value); if (scanned != 1) { abort(); } if (input_value == 0) { return default_value; } return input_value; }

int main() { printf("What is the seed? "); uint64_t input_seed = input_u64(DEFAULT_SEED);

printf("What is coeffecient1? "); uint64_t input_coeffecient1 = input_u64(DEFAULT_COEFFECIENT1);

printf("What is coeffecient2? "); uint64_t input_coeffecient2 = input_u64(DEFAULT_COEFFECIENT2);

printf("How many numbers? "); uint64_t numbers = input_u64(DEFAULT_NUMBERS);

seedMyRand(input_seed, input_coeffecient1, input_coeffecient2);

for (uint64_t number = 0 ; number < numbers; number++) { printf("%llu ", (unsigned long long) myRand() % MODULUS_CONSTANT); }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

Explain how seller responses are requested.

Answered: 1 week ago

Question

6. Are my sources reliable?

Answered: 1 week ago

Question

5. Are my sources compelling?

Answered: 1 week ago