W1292 Useful Randomness

From Coder Merlin
Revision as of 19:46, 19 June 2019 by Chukwuemeka-tinashe (talk | contribs) (Merlin moved page Project-1292 to W1292 Useful Randomness: Improved navigation)
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Random Bitmap
Kuntze-Konicz Fortune

Prerequisites[edit]

Research[edit]

Background[edit]

Unit circle 3
The value of π can be calculated by:

  1. Randomly throwing "darts" at a unit circle
  2. Counting the total number of "darts", N
  3. Counting the number of "darts" that fall within the unit circle, C
  4. The ratio of the area inside the circle to the total area is C/N
  5. The value of π is four times this value (because the area of the total square is 2 units x 2 units)

Exercises[edit]

Create a new directory in your ~/projects directory named "project-1292". Then, use emacs to edit a file named "main.swift" to perform the following exercises.

cd ~/projects
mkdir project-1292
cd project-1292
emacs main.swift
  1. Estimate the value of π by performing the above experiment
    1. Throw 100 darts. What result do you obtain?
    2. Throw 1000 darts. What result do you obtain? How is this different from your previous result?
  2. How many digits are you able to accurately estimate π by varying N?
  3. How important is it that the dart be "thrown" randomly?

Key Concepts[edit]

  • Random numbers meet the following two criteria:
    • Even distribution over a defined interval
    • Impossible to predict subsequent values based upon previous values
  • Random numbers can be very useful in certain circumstances