Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Many computing applications require a source of random numbers. Although no computer pro- gram (which is necessarily deterministic) can produce truly random numbers, programs

image text in transcribed

2. Many computing applications require a source of random numbers. Although no computer pro- gram (which is necessarily deterministic) can produce truly random numbers, programs can pro duce pseudo-random numbers that provide a reasonably good approximation of random numbers One simple and popular way to produce pseudo-random numbers is to use a linear co generator. It produces a sequence of random numbers Rk between 0 and m-1 from the recurrence relation ntial Here m is called the modulus, and a and c are positive integers called the multiplier and the increment. If m,a, and c are properly chosen, this algorithm can provide a decent pseudo-random nunber soirce. (a) Write a MatLab program that generates a vector of N pseudo-random numbers (where N is entered by the user) using the following form of the linear congruential generator: R+1 (936Rk 1399) mod 6655 MatLab's mod (A,B) function can be used to calculate A modulus B To start up the generator, an initial number for Ri, called the seed, must be chosen. This can be any number between 0 and 11979 (the maximum value the generator can produce). A quick and dirty way to generate a different seed each time the program is run is to generate it from the time of day using the MatLab clock function. clock returns a 6-element vector containing the current date and time, and we can extract the minutes and seconds from this function and use them to create a 4-digit number with the following lines of code: MinSec -fix(clock); seed 100*MinSec (5) MinSec (6) Finally, it's standard practice to have uniformly distributed random numbers be confined to the interval [0,1]. Have your program do this to your generated values by dividing each value by the maximum possible random value (6655 for our generator) that can be generated. Print out the results you obtain for N 50. You should also upload the final MatLab prograrn (b) To see if the random numbers generated are more or less uniformly distributed over the interval 0,1], add code to your program that creates a plot in which each random value is plotted along the X axis with a cross. If your vector of random numbers is called Urand, the plot is easily created with the code Y = ones (size (Urand)); plot (Urand,Y, 'x') (c) To get a somewhat more quantitative measure of whether the random numbers are uniformly distributed, add code to your program that sorts the random values into bins by counting how many N values are in the interval [0,0.1], how many are i (0.1,0.2], how many are in (0.2,0.3], etc. To do this, first create a 10-element vector called Bin, having values of zero for each element. Then write a for loop that looks at each random value, and, using a series of if...elseif...elseif blocks, increments the appropriate element of Bin. For example, if a randon value is >= 0 and 0.1 and

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

How does day care affect childrenpg12

Answered: 1 week ago

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago