Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedPlease Answer

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

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

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions