| CS182 -- Lab 5: Estimating Pi |
|
|
OverviewIn this lab, you should develop skills using functions. ProceduresWrite a program that will estimate pi by generating pairs of random numbers between zero and one. You may find it useful to use the equation for the area of a circle when making your estimate. You should estimate pi using 1) the random number generator found in the cstdlib library and 2) the random number generator described below. Power Residue Pseudorandom Number GeneratorThe power residue method is an alternative way of generating pseudorandom numbers. In order to generate pseudorandom integer numbers between 0 and 10n, we begin with an n-digit integer called the seed. In order to get a seemingly random sequence, the seed should be at least four digits long and not be divisible by 2 or 5. You may wish to select this number using the time() function in a way that is similar to setting the seed for the rand() function. The seed is then multiplied by (10n/2 - 3). The lowest n digits of the result is the pseudorandom number generated and is used as the seed for the next pseudorandom number in the sequence. For example, if we begin with a seed of 234567, we then multiply by (103 - 3) = 997 to get 233863299. The residue of this number is 863299, the second pseudorandom number generated. This is then multiplied by 997 to get 860709103. Therefore, 709103 is the next number generated. In order to successfully complete the laboratory assignment, you will need to write a function that implements the power residue pseudorandom number generator algorithm. Lab report (due 11:00pm, the day prior to week 7 lab)The lab report should be in your own words but need not be self-contained. Your report should include:
As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well. Your grade will depend on quality of design, clarity of code and documentation, as well as whether your program produces the correct results. If you have any questions, consult your instructor. |
| © 2001 Dr. Christopher C. Taylor | Office: CC-27C | Phone: 277-7339 | Last Updated: January 3, 2001 |
| I am responsible for all content posted on these pages; MSOE is welcome to share these opinions but may not want to. | |||