| 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.

> Suppose we have an urban space we want to populate with random passers-by. These should have a range of characteristics and not always be described in the same way; and once the player has noticed one, he should be able to look at her further, until another pedestrian crosses his path. "Uptown Girls" Riverside Drive is a room. "There's a pleasant late-afternoon view of the Hudson, and a snap in the air, and you would rather be here than anywhere." Instead of going a direction, say "Oh, you know where you're going; no need to deviate from the usual path." Instead of waiting, say "You stroll along enjoying the November crispness." It gets a little annoying to have a random event occurring every single turn of play, so let's introduce some randomness to determine how often the message appears: Every turn when a random chance of 1 in 3 succeeds: reset passerby; choose a random row in the Table of Atmospheric Events; say "[event entry][paragraph break]" Table of Atmospheric Events event "Slowly [a passerby] strolls by, turning to look at you as she passes." "Some [passerby] nearly bumps into you." "You dodge to avoid [a passerby]." "You weave around [a passerby], who has stalled to look into a window." "There's a ruckus as one of the ubiquitous taxis nearly collides with [a passerby] crossing the street." "[The passerby] beside you waves to a friend across the street." "To your left, [a passerby] drops her purse, and swears as she retrieves it." Hair color is a kind of value. A person has hair color. the hair colors are red-headed, brunette, blonde. Height is a kind of value. A person has height. The heights are tall, medium-height, short. Grooming is a kind of value. A person has grooming. The groomings are messy and tidy. To reset passerby: change the hair color of the passerby to a random hair color; change the height of the passerby to a random height; change the grooming of the passerby to a random grooming. The passerby is a woman in Riverside Drive. The passerby is scenery. Understand "woman" or "lady" as the passerby. The printed name of the passerby is "[if a random chance of 1 in 2 succeeds]woman[otherwise]lady[end if]". At this point we borrow some techniques from later to describe the woman with a random combination of characteristics, and to let the player refer to her by those traits: Before printing the name of the passerby: if a random chance of 1 in 4 succeeds, say "[height] "; if a random chance of 1 in 4 succeeds, say "[grooming] "; if a random chance of 1 in 4 succeeds, say "[hair color] ". Understand the hair color property as describing the passerby. Understand the height property as describing the passerby. Understand the grooming property as describing the passerby. If we also wanted each of those combinations to mean some more specifically-described woman: Instead of examining a passerby: repeat through Table of Passerby Descriptions begin; if hair entry is the hair color of the passerby and height entry is the height of the passerby and grooming entry is the grooming of the passerby, say "[description entry][paragraph break]"; end repeat. Table of Passerby Descriptions
> hair | height | grooming | description
> red-headed | tall | messy | "An older woman with long red hippie-hair poking out of a ponytail in straggles, and bent to hide how tall she is."
> red-headed | medium-height | messy | "A shaggy red-head with shingled hair."
> red-headed | short | messy | "Almost an urchin, and very young, with ginger hair and a smudged nose and far too many freckles."
> red-headed | tall | tidy | "A precise career woman with henna-red hair."
> red-headed | medium-height | tidy | "Her hair is red in the way that lollipops and fire trucks are red: not by nature but by art. The rest of her clothing is pretty ordinary, though."
> red-headed | short | tidy | "Thin and small in every sense, with chin-length red-hair. Even high heels do not bring her head much above your shoulder."
> brunette | tall | messy | "A Juno-esque woman with dark hair, wearing something resembling a tent."
> brunette | medium-height | messy | "An unremarkable woman with dark brown hair and the aura of needing a wash."
> brunette | short | messy | "There are mustard stains on the t-shirt of this short brown-haired woman. Estimated age ca. 40. Possibly homeless."
> brunette | tall | tidy | "A leggy brunette in business attire."
> brunette | medium-height | tidy | "Medium-height, brown-haired, generally nondescript."
> brunette | short | tidy | "A neat little dark-haired girl."
> blonde | tall | messy | "A tall blonde of about thirteen who looks as though she has not yet figured out how to get her wardrobe to catch up with her rate of growth. Her t-shirt and her pants are too short."
> blonde | medium-height | messy | "Black leather pants and the wall-o-hair look."
> blonde | short | messy | "One of those shocking platinum blonde types, with a tiger-patterned skirt. Reeally trashy."
> blonde | tall | tidy | "Elfin and severe, with perfectly straight hair falling to the middle of the back."
> blonde | medium-height | tidy | "A rounded, Marilyn-esque blonde."
> blonde | short | tidy | "Pin-precise in a blue-and-white striped suit and a boyish haircut."
Test me with "z / z / x passerby / z / z / x passerby".

Previous | Contents | Next