Question: Please answer this 5. Random number generators are important in numerical applications. One of the simpler methods is called the linear congruential method. Here, starting

 Please answer this 5. Random number generators are important in numerical

Please answer this

5. Random number generators are important in numerical applications. One of the simpler methods is called the linear congruential method. Here, starting with some initial number Xo (which is called the seed) and constants a, c and m, with all numbers non-negative integers, we can generate a sequence Xn+1 = (aXn+c) mod m Here, mod is the modulus or remainder operator, which in C++ is $. Obviously this generates a deterministic sequence, but for good choices of a, c and m the sequence looks like random integers between 0 and m- 1. One possible choice is m = 134456, a = 8121, c = 28411. Write a function int randlc(const int x) that uses these constants and does a single update of the sequence, so the function argument is Xn and the returned value is Xn+1. For some large N, e.g. 10,000, and some positive integer choice for Xo, use the function randlc to fill in a vector of size N with the sequence X to Xn. Then create a vector of size N and set the elements equal to X m-1 XN m-1 These values should approximate random numbers from the uniform distribution on the interval 0 to 1. This continuous distribution has mean 1/2 and variance 1/12. Use the functions from question 4 to check the mean and variance, and also check that the minimum and maximum values are close to 0 and 1 respectively. 5. Random number generators are important in numerical applications. One of the simpler methods is called the linear congruential method. Here, starting with some initial number Xo (which is called the seed) and constants a, c and m, with all numbers non-negative integers, we can generate a sequence Xn+1 = (aXn+c) mod m Here, mod is the modulus or remainder operator, which in C++ is $. Obviously this generates a deterministic sequence, but for good choices of a, c and m the sequence looks like random integers between 0 and m- 1. One possible choice is m = 134456, a = 8121, c = 28411. Write a function int randlc(const int x) that uses these constants and does a single update of the sequence, so the function argument is Xn and the returned value is Xn+1. For some large N, e.g. 10,000, and some positive integer choice for Xo, use the function randlc to fill in a vector of size N with the sequence X to Xn. Then create a vector of size N and set the elements equal to X m-1 XN m-1 These values should approximate random numbers from the uniform distribution on the interval 0 to 1. This continuous distribution has mean 1/2 and variance 1/12. Use the functions from question 4 to check the mean and variance, and also check that the minimum and maximum values are close to 0 and 1 respectively

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!