# Randomness and Simulation

Summary: In this laboratory, you will explore that `random` procedure using some fun Web services.

## Exercises

### Exercise 0: Preparation

a. Make a copy of `dicegame.ss` in your `public_html` directory.

b. Make the corresponding CGI script.

```#!/bin/bash
/home/rebelsky/bin/schemeweb dicegame.ss
```

c. Share the CGI script and make it executable.

```% share dicegame.ss
% share dicegame.cgi
% chmod a+x dicegame.cgi
```

d. Start DrScheme and load `dicegame.ss`.

e. Read through the procedures and make sure you understand what they do.

### Exercise 1: Experimentation

Verify that the `dicegame.cgi` script works.

### Exercise 2: Improving Code

Linda and Larry Leter have become addicted to the idea of putting lets around lambdas. Hence, they'd like to change the definition of `pair-a-dice` to

```(define pair-a-dice
(let ((dice (list (roll-a-die) (roll-a-die))))
(lambda () dice)))
```

a. What do you think about their idea?

b. Test their change from within DrScheme by repeatedly rolling a pair of dice (using `pair-a-dice`). Do you notice anything interesting about the results?

c. Test their change on the Web. Do you notice the same change? Why or why not?

### Exercise 3: Speeding Up the Game

Update `dicegame.ss` so that it reports the result of 10 rolls (or perhaps a user-selectable number of rolls) each time, rather than a single roll.

### Exercise 4: Favoring the House

a. Update `play-even-odd` so that the house wins \$2 rather than \$1 if the dice are odd.

b. Can you foresee any problems that might occur with this change? If so, which ones?

c. Experiment ot see if your claim is correct.

### Exercise 5: Seven or Eleven

Update `dicegame.ss` so that the player wins if the two dice total 7 or 11 rather than an odd number.

### Exercise 6: Or Doubles

Update `dicegame.ss` so that the player wins if the two dice total 7 or 11 or if both dice have the same value.

### Exercise 7: Changing Bets

Update `dicegame.ss` so that the player can choose the amount to bet.

### Exercise 8: Flipping Coins

Update `dicegame.ss` so that the game is based on flipping coins, rather than rolling dice. (You can choose an appropriate game.)

## History

Thursday, 19 September 2002 [Samuel A. Rebelsky]

Friday, 20 September 2002 [Samuel A. Rebelsky]

• Added a note in problem 2.

Monday, 4 November 2002 [Samuel A. Rebelsky]

• Some minor updates.
• Changed code for `game-page`.
• Never released.

Monday, 3 March 2003 [Samuel A. Rebelsky]

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

This document was generated by Siteweaver on Tue May 6 09:29:10 2003.
The source to the document was last modified on Mon Mar 3 09:32:45 2003.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003S/Labs/random-web.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu