Notes

Simulation

  • An imitation of a process or virtual expirament.
    • Example: flightsimulation to learn how to fly a plane without the risk
    • Testing and trying your code before finishing it.

Simulation vs expirament

  • Advantages:
    • Can be safer
    • More cost-effective
    • More efficient
    • More data in less time
  • Disadvantages:
    • Not as accurate as experiments
    • outside factors not included (ex: in rolling dice simulation gravity and air resistance)
  • When do you not use a simulation?
    • when a situation already has set results/data (won’t change)
    • examples: a score in a game, most purchased food, average yearly wage

Example:

  • Real life example of a simulation and experiment is the game we played of 4 corners

  • in code:

  • If statements show whether you are eleminated
    • Else tells you that you are still in
  • This was a simulation, because it was in code. When we do it in person, it is an experiment.
    • Nothing actually happened in the code, so it is a simulation.
  • Simulations are less accurate than expiraments, but they are more safer and puts things into perspective.

Rolling a Dice example

  • Simulation would just give you a randm number 1-6
  • Experiment would be affected by the surrounding area, the roll, annd gravity.

Hacks

Create an idea of a simulation (dont need to code it)

  • A possible idea for a simulation could be spinning a wheel with multiple sections that win you different prizes.
    • the code would split into 8 sections and these would be named S1, S2, S3, etc.
    • Each section would be a variable that is assigned to a different value like “iPhone”, “$100”, or “$1000”.
    • Then using “import random” and randomizing the choices it could simulate the possible landing spot for the spinner.
  • Advantage of simulation: It is efficient, it is quick, .
  • Disadvantage of simulation: It is boring and not very fun.

  • A real experiment of this would be actually spinning the wheel in real life and winning a prize based on the area you land in.

  • I feel that an experiment would be better than a simulation in this situation so you can actually have the fun of spinning the wheel rather than just clicking a button.

Simulation Quiz

Describe the rolling dice simulation

  • This is a simulation because the code gives you a random number 1-6 (like a dice block) an amount of times based on your input. This simulates the rolling of X dice blocks based on how many you chose to roll.

  • The advantages of this dice simulation is that it efficiently gives you an output of X numbers 1-6 based on how many dice you would want to roll.
    • It is quick and instant, anfd could be used if someone wants to play a game that uses dice, without any dice
  • Disadvantage is that you don’t get the thrill of rolling a dice.

  • I feel that the simulation is better in this situation, because it quickly gives you the output of however many dice you want to roll, rather than having to do it in real life.

Add feature onto the rolling dice

  • As you can see, I made the dice that are getting rolled, 21 sided dies rather than 6.
  • I also gave the user the option to roll 10 dies rather than only 4.

Extra Credit: Code the simulation

  • I coded a simulation of a spinning wheel :

  • This is a simulation because it simulates the spinning of a wheel.
    • It lands on a specific (randomly) though there is a better chance of landing on other colors with more sections.
    • In the simulation, I just happned to land on the section with the least probability of landing.
  • Its advantages are that it is efficient, quick, and is a nice example of a simulation
  • Disadvantage is that its pretty boring and doesnt actually do anything meaningful.