The creative potential of random

17 Aug '17

- randomness: highlights from history
- different
**types**of randomness - mapping: using randomness effectively

if you’re reading the slides at home, **watch the video**

musikalisches würfelspiel (18th century)

aleatoric music (20th century)

some of our labs have explored randomness in various forms

not all randomness is created equal

but this **isn’t** a maths lecture

- uniform:
`random([min], [max])`

- gaussian:
`randomGaussian()`

- discrete:
`random(choices)`

(Array version)

start with two numbers (`min`

and `max`

)

picks any number between those two numbers

all numbers in the range are **equally likely**

this last point is the key attribute of random numbers

picks a number *around* some middle point

numbers closer to that middle point are **more likely** than ones further away

named after Carl Friedrich Gauss

has other names: *normal distribution*, *bell curve*, etc.

sometimes there are a fixed number of outcomes, either equally likely or some more likely than others

e.g. coin toss, roll of the dice, football match

let’s have a look at the reference for
`random()`

again…

if `random()`

is passed one parameter which is an array, then the return value
will be one of the elements of the array, selected at random (all equally
likely)

if you want some outcomes (i.e. some elements of the array) to happen more often than others, there are a couple of tricks

you can add multiple identical elements to the array (think about why this works?)

```
var loadedDice = [1, 2, 2, 2, 2 3, 4, 5, 6];
var roll = random(loadedDice);
```

another approach: if you want one thing to happen e.g. 10% of the time, and something else to happen the other 90%

- use
`random(100)`

to get a random number between 0 and 100 - if the result is
*less than*10, do the first thing, otherwise do the other thing

mapping (I know the word “map” is overloaded in programming) in this context
means what do you *do* with the randomness

in my livecoding, I use random numbers to control/modulate: **pitch**,
**loudness**, **duration**, **rhythm**, **timbre** & more

in your sketches, think about how (and what kinds) of randomness you could use
to control: **position**, **size/shape**, **colour/transparency**,
**stroke/fill**, etc.

what’s the right balance between **predictability** and **surprise**?

choosing where to use randomness, where not to use it, and what type of
randomness to use: *this is where the art happens*

```
loadPixels();
for (var i = 0; i < pixels.length; i++) {
if (random() < 0.5) pixels[i] = 0;
else pixels[i] = 255;
}
updatePixels();
```

🤔