CS182 -- Lab 5: Estimating Pi



->Courses
->CS182
-->Homework
-->Quiz 1
-->Lab 1
-->Lab 2
-->Lab 3
-->Lab 4
->Lab 5
-->Lab 6
-->Project
->Electronic Submission
->MSVC Info
->Tentative Schedule
->Course Policies

[Courses]
[Rich][Home][Rich]
[Author]

Winter Quarter 2000-2001

Always multiply a software schedule by pi. This is because you think you're going in a straight line but always end up going full circle.
Anonymous

Overview

In this lab, you should develop skills using functions.

Procedures

Write 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 Generator

The 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:

  • A narrative describing how your program attempts to estimate pi.
  • A comparison between estimates of pi generated by the two different pseudorandom number generators, including an assessment of which method appears to be a better pseudorandom number generator.
  • Documented source code for your program. You may find it useful to use the code.bat and dump.bat batch files to produce one file containing all of your source code with the markup commands required by my electronic submission process.
  • Discussion (sample program output, problems you encountered (and how they were overcome), etc.)
  • A summary of your activity log indicating how much time you spent on each phase of the assignment. Please report the time in the following categories:
    • Design
    • Coding
    • Debug (before you think it's working)
    • Test (after you think it's working)
    • Documentation
    • Other
  • Conclusions (what you learned, suggestions of how the assignment could be improved, things you would have done differently, etc.)

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.