The concept of procedural generation is creation based on rules and algorithms, instead of manual construction. A common application is to create scenarios like a landscapes, but in such a way that is repeatable and predictable within a controlled setting. Additionally this normally results in high consistency. Though widely used in games including recent ones such as Minecraft and Rust, there are many other useful applications such as simulation modelling.

Ideally, the generation is a fractal method providing scalability. We will look at this in more detail in part 2.

To produce a set of proporties and attributes in a reproducible yet variable way, the common Random (or Rnd) function can be used. This function does not actually provide real random numbers, but psuedo random numbers. The 'random' numbers are generated, effectively implementing procedural generation. Additionally these are normally based on a start seed. So we want to create a set of properties, such as for different locations, each based on a seed. Next we want all of those to be based on one single master seed.

In simple pseudo code:

int masterSeed = 12345678

Random randomGenerator = new Random(masterSeed)

int[] locationSeeds = new int[100]

foreach (int locationSeed in locationSeeds)
    locationSeed = randomGenerator.getNext()

As this example illustrates, changing the masterSeed will result in a different set of location specific seeds. Next, for each specific location, different properties can be generated, in a consistent way - if and when they are required:

Random randomGenerator = new Random(locationSeed)

foreach (Property property in properties)
    property = randomGenerator.getNext()

The method used for creating fractal terrain is Midpoint Displacement, though it is worth mentioning Perlin noise is another popular method used for this. Midpoint Displacement in one dimension is simple (see images below), starting with two points (1), and a straight line connecting these (2), find the midpoint on the line (3) and displace the new point up or down with a particular magnitude(4). There are now 2 connecting straight lines, drawn over 3 points (5). The process continues iteratively, finding the next midpoint between previous points in turn, and displacing these with a decreasing magnitude. For two dimension, the diamond-square algorithm is applied.
Midpoint Displacement illustration



Procedural Content Generation in Games

Generating Random Fractal Terrain

Fractal landscape

Diamond-Square algorithm

Perlin noise