Generate a series of pseudo random numbers

Assignment Help C/C++ Programming
Reference no: EM13909752

You will write a program to generate a series of pseudo random numbers, using a linear feedback shift register method. You will start with an arbitrary number (not zero) x with a representation in n bits.

If x = 15 and n = 4, then x = 1111. Then you will select a pair of bits, say bits 0 and 1, take their "xor" producing a new bit - in this case a 0. The number x will then shift to the right, with the new bit becoming the new high bit - in this case 0111.

The process continues in this manner to produce a random set of bits. With four bits, we can only have up to 15 unique transitions before repetitions begin, or 2n - 1. With n = 32, the number of random bits has a much greater potential.

The numbers actually produced by the "shifting" cannot be considered "random", since all but one of the bits overlap from each succeeding number. However, if we want to produce, say 100 6-bit numbers, then we need to shift the bits into an 6- bit register. We can then save its "value" in an array of 100 integers.

Then we should produce the output which will display the distribution. Random numbers should follow a uniform distribution. Using a 32-bit generator does not guarantee 2n - 1 random bits. For good results try using bit combinations 0/4, 0/7, 0/25, 0,26, 0/29.

Example:

11001110 -> 11100111 -> 01110011 -> 10111001 -> 11011100 ->
11101110 -> 11110111 -> 01111011 -> 10111101 -> 01011110 -> etc

Three random 4-bit numbers produced: 11, 13, 4, .... Try "tapping" different bit combinations, as well as the ones I suggested. To verify that the set of numbers you generated are really pseudo random, you will test them using the statistical (Chi-Square) χ2 test. You will generate 10,000 numbers in the 0-63 range. Then N = 10,000 and r = 64. You will then compute χ2 by the formula

χ2 = 0≤ i < r∑(fi - N/r)2/ (n/r)

If χ2 is in the range of r ± 2√r, we conclude that distribution is indeed random. Otherwise it may not be. In your program, you will implement a random number generator module. Then the program will request 10,000 random numbers in the range of 0-25. It will then apply the test to see if the numbers are random. You should apply the test a number of times because it has a 1/10 chance of showing failure even when the random distribution is successfully generated.

You will implement the random number generator as a RandomGenerator C++ class. The constructor will have to initialize the seed value. Subsequent calls to the random( ) method with integer parameter range will return a random value in the range between 0 to range-1 inclusive. The tapping bits should be set by default (in the constructor).

You will create a class called RandomGenerator. You will use inheritance to create two subclasses, UniformGenerator and ExponentialGenerator. The 1st will generate random integers in a range from 0 to n -1. The 2nd will generate random real numbers in an exponential distribution with parameter lambda. The class hierarchy will look as follows:

1930_Series of pseudo random numbers.png

Be sure that your design factors the common behaviors of all generators into the superclass, RandomGenerator. After running your program several times you will take the output from the file you generated, and put it though a test. The exponential numbers should follow the exponential distribution with parameter lambda, λ. You should take the numbers, and graph them in a spreadsheet, such as Excel. The shape of your distribution will reveal the quality of your generated numbers. A histogram may be a good way to visualize the numbers. It is well known that the mean of the exponential distribution is 1/ λ. For example, if λ = 0.5, then your mean should be quite close to 1/ 0.5 = 2. When you print out your mean, you should get close to 2.0000, but not exactly 2.0000.

The uniform numbers will tend to have a similar number of occurrences for all numbers in the range. You should use a spreadsheet again to show your result. In addition, you should also include the χ2 test along with the uniform numbers.

The for the UniformGenerator does not need any parameters. The ExponentialGenerator needs the lambda (λ) parameter.

Reference no: EM13909752

Questions Cloud

Calculate the values of x(?) and y(?) : On a two-dimensional sketch for a given α, show the values of X(ω) and Y(ω) for which ω ∈ D(n). Hint: This set of values should be bounded by a staircase function.
Ndirect materials requisitioned : Refer to the information in QS 20-2 and QS 20-3. Blanche's Boxes requisitioned $ 9,000 of indirect materials from its raw materials and used $ 10,000 of indirect labor in its production of boxes.
How do the largest us stock markets differ : How do the largest U.S. stock markets differ? Out of those choices, which would be the smartest private investment option, in your opinion? Why
The following refers to units processed in sunfllower : Compute the total equivalent units of production with respect to labor for March using the weighted average inventory method.
Generate a series of pseudo random numbers : You will write a program to generate a series of pseudo random numbers, using a linear feedback shift register method. You will start with an arbitrary number (not zero) x with a representation in n bits.
Compute the total equivalent units of production : Compute the total equivalent units of production with respect to labor for July using the weighted average inventorymethod.
What are the betas of stocks x and y : Stock A has an expected return of 12% and a standard deviation of 40%. Stock B has an expected return of 18% and a standard deviation of 60%. The correlation coefficient between Stock A and B is 0.2. What are the expected return and standard de..
Transferred completed products with a cost : Prepare journal entries to record the following production activities.
What is a characteristic polynomial : What is A's characteristic polynomial? What are A's eigenvalues? For each eigenvalue identified in (b), find a corresponding eigenvector. In each case, show your working

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to read data from input file

Write a program to read data from input file.  The first value read is the number of numbers to be read next.  Calculate average of those numbers and write to an output file the numbers read and the average.  Repeat this process until end of file. Us..

  Implement a graphics system that has classes

Implement a graphics System that has classes for various figures: rectangles, squares, triangles and circles. A rectangle has data members height, width, color , and center point. A square has center point and an edge and color

  Need to convert this c code to mips

You need to convert this C code to MIPS - The subsequent is a sample output (user input is 2): Enter an integer: 2 The count of the integers that are greater than 2 is: 3 You have to assure the requirements specific in the instruction.

  Create a c++ function named pathexists

Write a C++ function named pathExists that determines whether or not a there's a path from start to finish in a 10x10 maze. A 2-dimensional 10x10 character array of Xs and dots that represents the maze. Each 'X' represents a wall, and each '.' rep..

  Computes interest on a credit card balance

Write a C++ object oriented program which computes interest on a credit card balance. The task is done with a function that accepts initial balance, monthly interest rate, number of months for which the interest must be paid. The value returned is..

  Write a program to create a console application

Write a program to create a console application that allows the user to access sunrise/sunset almanac data for up to 30 days for a given choice of cities

  1 write a c program that takes an eastern standard time

1. write a c program that takes an eastern standard time in hours minutes and secondsand prints it out in central

  Evaluates the gross pay of a set of employees

Write a C program that will calculate the gross pay of a set of employees - determines both the overtime hours (anything over 40 hours) and the gross pay, and outputs

  Compute the average of each row

Write a program that prompts the user to enter 15 double numbers from the keyboard and save them into a 3 by 5 array in the main ( ). Then call a user-define function to compute the average of each row and print the original matrix and average of ..

  Write a program code to compute and build a table of reynold

Write a program code to compute and build a table of Reynolds numbers at flow velocities varying from 100 to 1000 ft/sec (at increments of 100)

  Display the complete fibonacci sequence

Display the complete Fibonacci sequence until u reach a value less than or equal one million - display the count of how many numbers are in that sequence between 1 and 1000000

  Write a corresponding if else statement

The mathematical operation max(x,y,w,z) can be represented by using the conditional expression operator, as in:  max = (x > y && x > z && x > w) ? x : ((y > z && y > w) ? y : ((z > w) ? z : w))  Write a corresponding if else statement that is equival..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd