# Class 29: Simulation

Reading: Simulation. Lab: Simulation. Back to Pause for Breath. On to Local Procedure Bindings.

Held Monday, March 12, 2001

Summary

Today we consider how to make DrScheme simulate potentially unpredictable events, like the rolling of dice or the flipping of coins.

Due

Assignments

Notes

• I spent much of the weekend working on taxes. Oh, what fun. Hence, I did not get exams graded. It looks like those of you who turned in exams late will have to wait until after break (as I said you might).
• I may be playing with the syllabus this week.
• Those of you who want to spend some of break getting ahead can check out the course at a glance and then look for the readings from last semester or from one of the other sections of the course.
• Note that week 9 (on GIMP) is all new.
• A few of you asked for more information on `let`. I've started a short handout.

Overview

• The Problem of Simulation
• Scheme's `random` procedure
• Simulating the roll of dice
• Lab

## Simulation

• At times, we write programs to model real-world situations:
• The effect of pollutants on a lake
• The waiting time in line at Wal-Mart
• The playing of a card or dice game
• Each of these situations has some aspect of unpredicatability (even if we ignore the butterfly flappings of chaos theory)
• Can we write such programs in Scheme?

## Random

• Scheme provides a simple procedure, `random`, to provide some fodder for simulations and any other times that you want to play with unpredictable behavior.
• `(random n)` produces an "unpredictible" number in the range [0 .. n-1].
• That's all you need to know right now.

## Dice

• Here's a simple simulation problem: Simulate the roll of a single six-sided die.
• Yes, die is the singular of dice
• Here's one possibility
```(+ 1 (random 6))
```
• See the reading for an alternative.

## History

Friday, 12 January 2001

• Created generic outline format for class.

Sunday, 11 March 2001

• Filled in the details.

Back to Pause for Breath. On to Local Procedure Bindings.

Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Wed May 5 12:15:02 2004.
This page may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/outline.29.html`.