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...
-
Jack is starting a business that he expects to produce $60,000 of income this year before compensating Jack for his services. He has $1,000 of other income and itemized deductions totaling $10,000....
-
The annual report is considered by some to be the single most important printed document that companies produce. In recent years, annual reports have become large documents. They now include such...
-
What do you know about the mathematical value of the annual worth of a project under each of the following conditions? a. The present worth of the project is greater than 0 . b. The present worth of...
-
Breyer Company purchased packaging equipment on January 3, 2010, for $101,250. The equipment was expected to have a useful life of three years, or 25,000 operating hours, and a residual value of...
-
How much energy does a male Jackson's widowbird of mass 45 g expend when jumping to a height of 1.0 m during its mating ritual? Neglect all losses due to air resistance
-
Your parents are considering investing in Apple Inc. common stock. They ask you, as an accounting expert, to make an analysis of the company for them. Financial statements of Apple are presented in...
-
On January 1, 2020 Lessor Corporation enters into a lease agreement with Lessee Ltd: Annual lease payment due at the beginning of each year, starting Jan 1, 2020 $ 24,324.43 Residual value...
-
Shadow Corp. has no debt but can borrow at 7.8 percent. The firm's WACC is currently 9.6 percent, and the tax rate is 22 percent. a. What is the firm's cost of equity? (Do not round intermediate...
-
Teocalli Burritos owns a fleet of food delivery trucks that provide food services to a variety of local entertainment events. Management for the company provided you the following information...
-
taxes (EBIT) of $2.9 million. If a recession occurs, each firm will generate earnings before interest and taxes (EBIT) of $1.3 million. Steinberg's debt obligation requires the firm to pay $920,000...
-
If you deposit $ 2 5 0 0 two years from now in a bank account that pays 4 % compounded annually, how much will you have five years from now?
-
calculate WACC 2 3 4 balance sheet bank debt 50 cash 20 other current liabilities 20 other current assts 20 10% bond, due 2032 100 fixed assts 250 stockholders equity 120 total liabilities $290 total...
-
Consider following relation with schema R(A, B, C, D) and functional dependencies: 1. ABC, CD, and DA. 2. BC, and BD. 3. ABC, DC, and B-D. a. List all candidate keys b. Check whether the relation is...
-
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?
-
Explain why some employees are not comfortable being team players.
-
It is important to learn how to develop a comprehensive, clearly articulated team charter. Assume that you and your fellow students are a team in an organization (you choose the kind and size of...
-
Define effective listening .
Study smarter with the SolutionInn App