| Chapter 8: Change |

| 8.16. Randomness

Sometimes we want to introduce random behaviour into play. We usually do this by generating random values, and then acting differently depending on what they are. The following:

> a random number from 2 to 5

produces, as it suggests, a random number drawn from the choices 2, 3, 4 or 5, each of which is equally likely to come up.

We can also use random conditions:

> if a random chance of 2 in 3 succeeds then ...

Here is a rule which applies only 15% of the time:

> Instead of waiting when a random chance of 15 in 100 succeeds: ...

If we make a new kind of value, we can also take random values from it, as in the following miniature world:

> "Weathering"

> A cloud pattern is a kind of value. The cloud patterns are cumulus, altocumulus, cumulonimbus, stratus, cirrus, nimbus, nimbostratus.

> The Mount Pisgah Station is a room. "The rocky peak of Mt. Pisgah (altitude 872m) is graced only by an automatic weather station. The clouds, close enough almost to touch, are [a random cloud pattern]. Temperature: [a random number from 7 to 17] degrees, barometric pressure: [950 + a random number from 0 to 15] millibars."

The value "a random cloud pattern" produces a random choice from the seven cloud patterns, each equally likely.

Testing IF which makes random choices can be rather frustrating, because a problem showing up on one attempt may not show up on another. To ease testing, the following sentence will "fix" the process of generating these random numbers so that they are not random at all - the same sequence of random numbers will be produced on each run.

> When play begins, seed the random-number generator with 1234.

The seed value "1234" can be anything positive; a different sequence of random numbers will be produced for each different seed value. A seed value of 0 restores the RNG to properly random behaviour again.

106
| Example Uptown Girls A stream of random pedestrians who go by the player.

Previous | Contents | Next