Difference between revisions of "W1292 Useful Randomness"

From Coder Merlin
Line 8: Line 8:


== Research ==
== Research ==
* [https://en.wikipedia.org/wiki/Random_number_generation Random Number Generation]
* [https://en.wikipedia.org/wiki/Random_number_generation Random Number Generation] (Wikipedia)
* [http://theconversation.com/how-random-is-your-randomness-and-why-does-it-matter-59958 How Random is Your Randomness?]
* [http://theconversation.com/how-random-is-your-randomness-and-why-does-it-matter-59958 How Random is Your Randomness?]
* [https://theconversation.com/the-search-for-the-value-of-pi-55744 The Search for π]
* [https://theconversation.com/the-search-for-the-value-of-pi-55744 The Search for π]
* [https://developer.apple.com/documentation/swift/int/2995648-random Random Function for Int] (Swift Documentation)
* [https://developer.apple.com/documentation/swift/double/2995409-random Random Function for Double] (Swift Documentation)


== Background ==
== Background ==

Revision as of 18:36, 5 April 2020

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)

Prepare[edit]

Create a new directory in your ~/Experiences directory named "project-1292". Use emacs to edit a file named "main.swift":

zay-vin@codermerlin:~$  cd ~/Experiences

zay-vin@codermerlin:~/Experiences$  mkdir project-1292

zay-vin@codermerlin:~/Experiences$  cd project-1292

zay-vin@codermerlin:~/Experiences/project-1292$  touch main.swift

zay-vin@codermerlin:~/Experiences/project-1292$  makeSwiftMake

zay-vin@codermerlin:~/Experiences/project-1292$  emacs main.swift


Hint.pngHelpful Hint

You can run your program with:

zay-vin@codermerlin:~/Experiences/project-1292$  run


ObserveObserveIcon.png
Observe, Ponder, and Journal: Section 1

Complete your program, then answers these questions.

  1. Estimate the value of π using your program
    1. Throw 100 darts (N = 100). What result do you obtain?
    2. Throw 1000 darts (N = 1000). What result do you obtain?
  2. How is the second result different from your previous result?
  3. How large should N be to accurately estimate π to five digits?
  4. How important is it that the dart be "thrown" randomly?

Exercises[edit]

Template:W1292-Exercises

Key Concepts[edit]

Key ConceptsKeyConceptsIcon.png
  • 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