Question: Please use mathlab or python to solve and show all steps with code and solution. 1. Choose an m e (150, 151,... 5000) and an
1. Choose an m e (150, 151,... 5000) and an a e [2,3,... , m-1) so that the linear congruential generator R (aRn-1) mod m (LCG) has full period. [Matlab has a function i sprime that you might find useful.] Report your choice of a and m. For the seed Ro 1, generate R,... Rm-1 and define N to be the number of the R,'s that are equal to k. More formally What should N be for each k. . m 1? Attach a plot of N; versus k for k 1,...,m-1. Different PRNGs in Matlab The latest version of Matlab has many different methods for creating pseudo-random uniform(0, 1) sequences. You can create multiple sequences (often called "streams") using different seeds or different methods and compare them. Here's how to create 3 different streams using 3 different methods. methodlRandStream ('mcg16807') method2 RandStream ('swb2712) method3 RandStream ('mt 19937ar) Method 1 was Matlab's default before 1995. It is a LCG with m231 1 and a 7%. It is too simple for modern applications. Method 2 was Matlab's default from 1995 to 2006. It is not a LCG and it is awful. I once spent many hours debugging before I realized that the problem was with this PRNG. Method 3 is the Mersenne Twister, which is currently a very popular PRNG and which is Matlab's default since 2007. Assuming you ave a recent version of Matlab, then if you just use rand in Matlab, then you will get method 3 without having to specify anything. To generate an r x c array of pseudo-random numbers using one of these streams and store it in the matrix U, type U rand (method?,x,c) where you replace the ? with one of the numbers 1,2. or 3 to get the desired method. [On later homework sets, when we are finished exploring PRNGs and just want the best PRNG, you can use U rand (r, c) i without specifying a method. This uses the default- method 3, in this case- which seems to be the best of Matlab's choices.] Demo Convince yourself that the PRNGs are deterministic. For example, create two copies of method 3, say method3a RandStream ('mt19937ar'): and met hod3b RandStream('mt 19937ar Now rand (method3a) and rand (method3b) should behave identically. Call them repeatedly to verify. Four different PRNGs A. The LCG that you created in problem 1 fafter converting to (0, 1) by dividing each Rn by m]. B. Matlab method 1 above. C. Matlab method 2 above. D. Matlab method 3 above. The law of large numbers Recall that the law of large numbers (LLN) states that ! as n oo for any iid sequence X i X2 for which Eh(X) exists. So if a pseudo-random sequence U1,U2,.., Un behaves like an iid Uniform(0, 1) sequence, then we better have k 1 for large n where U is Uniform(0,1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
