# Class 13: Random Fun

Back to CGI Scripting, Continued. On to Repetition with Recursion.

Held Friday, September 20, 2002

Summary

Today we explore some fun applications of the `random` procedure in the context of CGI scripts. We will spend some of today's class on a different learning technique: group design of a Web service.

Assignments

Notes:

• Welcome to any visiting parents.
• The problem with Web pages appearing in an Courier was due to an error in my sample HTML. Where we use `<lang="eng">`, we should be using `<lang="en">`.
• Are there any questions on homework 3?
• Warning: Last Friday's class was Friday the 13th. This Friday's class is Class #13.

Overview

## Review: The `random` Procedure

• The `(random n)` procedure generates an unpredictable number between 0 and n-1.
• You can use that result as you'd use any other number.
• You can add to it.
• You can use it to select between elements in a list.
• To roll a die
```(+ 1 (random 6))
```
• To pick a random word
```(list-ref (list word0 word1 word2)
(random 3))
```

## A Dice Game

• We'll begin class by thinking about the design of a Web-based dice game.
• The player has an account of some amount of money.
• Each round, the computer rolls two dice.
• If the sum is even, the computer wins.
• If the sum is odd, the player wins.

## Key Questions

• How do we roll two dice?
• How do we keep track of the amount the player currently has?
• How do we start the game?
• What goes on each Web page?

## Lab

• We'll explore this game in the lab.

## History

Thursday, 29 August 2002

Back to CGI Scripting, Continued. On to Repetition with Recursion.

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 Mon Dec 2 08:41:02 2002.
The source to the document was last modified on Tue Sep 10 15:07:31 2002.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Outlines/outline.13.html`.

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

Samuel A. Rebelsky, rebelsky@grinnell.edu