The Utopian Coding Society (UCs)' is evaluating the how different programming languages handle pseudo-random number generation...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The Utopian Coding Society (UCs)' is evaluating the how different programming languages handle pseudo-random number generation and very large values. You decided to contribute to this under- taking by creating a program to visualise the "randomness" of psuedo-random number generation methods. You decided to first analyse the Linear Congruential Generator (LCG). The formula for the LCG is: rn+1 (a * In c) mod m %3D where rn+1 is the next term, rn the previous term and a, c and m are constants. You must do the following: • Create a class called LCGenerator and place it in the csc2a.ucs.random package. • Create a method nextInt in LCGenerator, which must take no parameters, and must generate a random integer value using the LCG formula. • LCGenerator must have the constants A, C and M, as well as an integer seed value, as private attributes. • The values for the constants should be as provided in the next page. • The seed value must be set during creation (using a constructor) and must be used as ro when nextInt is called for the first time. • You must use the LCGenerator to generate random {x, y} coordinates which you must plot on a canvas. Constants for the Microsoft LCG formula A 214013, C = 2531011, M = 2^31 In order to plot the randomly generated coordinates, you must create a SimulationCanvas class in the csc2a.ucs.ui package in the following way: • SimulationCanvas must extend javafx.scene.canvas.Canvas and must have an ArrayList of Integer[] as a private attribute. One Integer[] must store one {x, y} coordinate. • Create a setPoints method which you will use to update the ArrayList. • Create a redrawCanvas method which you will use to draw the coordinates on a canvas using a GraphicsContext. • setPoints must call redrawCanvas after updating the ArrayList. Here is an example of how the points should be drawn on the canvas: Linear Congruential Generator Visualizer O X Plot Values Create a Main class and do the following: • Create an LCGenerator instance using a seed value of your choice and generate 10000 random {x, y} coordinates. • Note: Becuase the given formula can potentially generate integers that are larger than the maximum value for an integer in Java, it is possible for the nextInt method to return neg- ative integers in some cases. Therefore, after generating {x, y} coordinates, you must first check that they are both not negative before storing them (if one of the coordinates is neg- ative, you may simply skip to the next iteration. You not have to call nextInt again). • Note: Remember to mod the random number with the canvas' width (for x-coordinates) and height (for y-coordinates) to make sure that all your coordinates are within range. The Utopian Coding Society (UCs)' is evaluating the how different programming languages handle pseudo-random number generation and very large values. You decided to contribute to this under- taking by creating a program to visualise the "randomness" of psuedo-random number generation methods. You decided to first analyse the Linear Congruential Generator (LCG). The formula for the LCG is: rn+1 (a * In c) mod m %3D where rn+1 is the next term, rn the previous term and a, c and m are constants. You must do the following: • Create a class called LCGenerator and place it in the csc2a.ucs.random package. • Create a method nextInt in LCGenerator, which must take no parameters, and must generate a random integer value using the LCG formula. • LCGenerator must have the constants A, C and M, as well as an integer seed value, as private attributes. • The values for the constants should be as provided in the next page. • The seed value must be set during creation (using a constructor) and must be used as ro when nextInt is called for the first time. • You must use the LCGenerator to generate random {x, y} coordinates which you must plot on a canvas. Constants for the Microsoft LCG formula A 214013, C = 2531011, M = 2^31 In order to plot the randomly generated coordinates, you must create a SimulationCanvas class in the csc2a.ucs.ui package in the following way: • SimulationCanvas must extend javafx.scene.canvas.Canvas and must have an ArrayList of Integer[] as a private attribute. One Integer[] must store one {x, y} coordinate. • Create a setPoints method which you will use to update the ArrayList. • Create a redrawCanvas method which you will use to draw the coordinates on a canvas using a GraphicsContext. • setPoints must call redrawCanvas after updating the ArrayList. Here is an example of how the points should be drawn on the canvas: Linear Congruential Generator Visualizer O X Plot Values Create a Main class and do the following: • Create an LCGenerator instance using a seed value of your choice and generate 10000 random {x, y} coordinates. • Note: Becuase the given formula can potentially generate integers that are larger than the maximum value for an integer in Java, it is possible for the nextInt method to return neg- ative integers in some cases. Therefore, after generating {x, y} coordinates, you must first check that they are both not negative before storing them (if one of the coordinates is neg- ative, you may simply skip to the next iteration. You not have to call nextInt again). • Note: Remember to mod the random number with the canvas' width (for x-coordinates) and height (for y-coordinates) to make sure that all your coordinates are within range.
Expert Answer:
Answer rating: 100% (QA)
Step1 create LCGeneratorJava and add below code Package csc2aucs random Public class LCGenerator Pri... View the full answer
Related Book For
Business research methods
ISBN: 978-1439080672
8th Edition
Authors: William G Zikmund , Barry J. Babin, Jon C. Carr, Mitch Griff
Posted Date:
Students also viewed these programming questions
-
You are given the multiplicative congruential generator x0 = 1 and xn+1 7xn (modulo 13) for n = 0, 1, 2, . . . . (a) Calculate xn for n = 1, 2, . . . , 12. (b) How often does each integer between 1...
-
In evaluating different measuring instruments, one must first determine whether there is a systematic difference between the instruments. Lenses with several different powers were measured once each...
-
A random number generator is used to generate a real number between 0 and 1, equally likely to fall anywhere in this interval of values. (For instance, 0.3794259832 c is a possible outcome.) a....
-
Calculate the dollar proceeds from the FIs loan portfolio at the end of the year, the return on the FIs loan portfolio, and the net interest margin for the FI if the spot foreign exchange rate has...
-
Consider the following note payable transactions of Tube Video Productions. 2014 Mar. 1 Purchased equipment costing $ 80,000 by issuing an eight-year, 12% note payable. The note requires annual...
-
A cylindrical gas tank 1 m long, inside diameter of 20 cm, is evacuated and then filled with carbon dioxide gas at 25C. To what pressure should it be charged if there should be 1.2 kg of carbon...
-
By what criterion should a policy of reinvesting cash flow be judged?
-
For each of the following situations, two scenarios are described, labeled A and B. Choose which scenario is descriptive of a setting corresponding to activity-based responsibility accounting and...
-
An eraser weighs 17.4 grams. A box with 44 erasers weighs 0.769 kg. What is the weight of the box alone? Please express your answer in grams.
-
A secret service courier carrying a briefcase with the codes to the USA's nuclear defense system has a mean delivery time of 62 minutes with a standard deviation of 13 minutes. What is the...
-
Given the generator polynomial of g(z) = z+z+1, draw the corre- sponding BCH[15,11,3] encoder's schematic.
-
The Alpha Division of Mayfield Company had an operating income of \($135,000\) and net assets of \($560,000\). Mayfield has a required rate of return of 14 percent. Alpha has an opportunity to...
-
The mood at the April 29, 2009, Bank of America (B of A) shareholder meeting was tense. Stock prices had plummeted from a high of over \($52\) in 2006 to a close the previous day of \($8.15.\)...
-
A large open water tank has a horizontal cast iron drainpipe of diameter \(D=1 \mathrm{in}\). and length \(L=2 \mathrm{ft}\) attached at its base. If the depth of water is \(h=3 \mathrm{ft}\), find...
-
The following information is provided for the Asteroid Antenna, Corp., which manufactures two products: Lo-Gain antennas, and Hi-Gain antennas for use in remote areas. Asteroid plans to produce 200...
-
Hi-Tech Manufacturing paid cash to purchase the assets of an existing company. Among the assets purchased were the following items: Hi-Tech's financial condition just prior to the purchase of these...
-
Question 3 of 3 < > 0.81/3 : Show Attempt History Current Attempt in Progress Ivanhoe Company closes its books on its July 31 year-end. The company does not make entries to accrue for interest except...
-
Draw the appropriate control flow graph of the given pseudocode.Make sure to only use one number for blocks of code which are all sequential and when the first line is executed, all of those lines...
-
A researcher uses multiple regression to predict a clients sales volume based on gross domestic product, personal income, disposable personal income, unemployment, and the consumer price index. What...
-
A researcher expects the population proportion of Cubs fans in Chicago to be 80 percent. The researcher wishes to have an error of less than 5 percent and to be 95 percent confident of an estimate to...
-
What key questions help resolve the question of whether or not research participants serving as subjects in an experiment are treated ethically?
-
Danny Sutton Manufacturing Company is considering three new projects, each requiring an equipment investment of \($24,000\). Each project will last for 3 years and produce the Following " cash...
-
Caan Oil Company is considering investing in a new oil well. It is expected that the oil well will increase annual revenues by \($120,000\) and will increase annual expenses by \($80,000\) including...
-
Padong Corporation is considering purchasing a new delivery truck. The truck has many advantages over the company's current truck (not the least of which is that it runs). The new truck would cost...
Study smarter with the SolutionInn App