From: Tutorial: Sampling And Measuring Generators

In this part we’ll see how we can understand the generative space of a procedural generator by sampling it.

Simple Generator

Sampling and Representation

Our hope is that our sample resembles the larger group we took it from, and so if we measure something about the sample it will be similar to measuring the entire group. But as we increase the size of the sample, any measurements we take from the sample get closer to being what we would see if we measured the original, large group.

The interactive example below automatically samples 200 levels and calculates the average number of enemies, visible in the bottom-left of the window.

Simple Sampling

What we see is that as we increase the chance of an enemy spawning in any tile, the average number of enemies increases in our sample - which makes perfect sense! We didn't really need sampling to know this, we probably had a hunch already, but it's good to confirm our ideas.

Summing Up

Sampling

Sampling is a way of looking at a small part of something to get an idea of what the rest of it is like. We can sample procedural generators by generating lots of outputs randomly. Measuring things about the sample can tell us what the generator is like.

The bigger our sample is, the more accurate our analysis will be. But bigger samples also take longer to generate. This can be really boring to do by hand, but we can write code to automate the process.

Analysing Samples

If we sample a generator before and after making a change, we can use the results from the samples to get extra information about what effect the change we made had on the generator.

Sometimes this is useful for confirming something we already knew; sometimes this helps us learn relationships between different parts of our code; and sometimes it totally surprises us with something we didn't expect!

Sampling Isn't Always Enough

At the end, we discussed a couple of important things to remember about sampling: that we can't always measure exactly what we want to; and that sampling can also mislead us.