# Simulation & Design¶

Lab Assignment: Simulation & Design

Consider you are standing at a street corner, in a city where the streets are laid out in a very regular grid pattern. At this point you randomly choose and intersection to turn on to (left, right, forward or backward - let’s say). You walk further to another intersection and make the same random choice. Rinse, lather, repeat. When you finally stop, your winding path is some direct distance away from your starting point. This is an example of a random walk. It’s a probabilistic simulation of certain statistical systems (like photons inside a star, or Brownian motion of molecules).

In n steps, how far do you expect to be from your starting point? Write a program to help answer this question.

The requirements for this assignment are straightforward:

1. You will need to use function(s) from the Python random module.
2. Your main function will be used to ask for user input and loop, and perform m number of walks.
3. You will write a function called random_walk_2d that will perform a random walk of n steps.

The distance from your starting point (origin) is a unit-less measurement, don’t worry about giving the distance any real physical unit.

### Output¶

Because random processes are involved, your results may vary, but the output should look like the following example runs.

A simulation of 3 different walks, each taking 45 steps:

Simulation of two dimensional random walk

How man walks should I do? 3
How many steps should I take on each? 45
Average distance from start: 5.26


A simulation of 50 different walks, each taking 1000 steps:

Simulation of two dimensional random walk

How man walks should I do? 50
How many steps should I take on each? 1000
Average distance from start: 29.64


## Submission Requirements¶

Your file is required to be named lab_simulation_design.py.

The following is the grading rubric for this lab to be used by the course graders. The lab is worth 100 points.

Note: There may be additional criteria for grading, this is just a summary of the major rubric items.

Type Description Point Loss (Max)
[General]
SyntaxError Exceptions A program that doesn’t even start due to syntax errors. -30
Docstrings Missing proper lab header (e.g. no name, lab section, etc) -10
main() Your program should have main() as the first-called function -10
PEP 8 Style Egregious problems with your code styling -10
Incorrect Filename Follow the submission instructions -5
Commenting Insufficient or excessive comments -5
[Lab Specific]
Functions Two functions are required: random_walk_2d(), and main. -10 each/missing
Monte Carlo Not using random numbers properly, a la Monte Carlo-style simulation. -20 points

### Extra Credit¶

Extra credit work must be submitted in what would be your original submission file for the assignment. All extra credit code must be clearly commented in order to receive any points.

• +15

Use graphics.py to draw each walk, slowly, in a graphics-based window.