## Introduction

In Shepherding Random Numbers
I introduced few ways to use random numbers to create interesting
behaviour. Here I will extend upon those ideas a little, so I recommend
reading that first. Once again this is not a rigorous look at the
mathematical concepts, it is just a collection of possible *generative* techniques.

*This text relies on Javascript animations (Canvas). They
should work on most devices, but please let me know if you
experience any issues.*

*You can click or tap all animations to restart
them.*

## Random Walk

In the previous post we already introduced a version of the behaviour typically referred to as a Random Walk. (But I never named it. Sorry.) There are multiple definitions and versions of Random Walks. Below is a simple version in two dimensions.

## Multiple

Let's see what it looks like when we distribute several, independent, nodes in a grid, and animate them all with random walks.

## Grid

Things look quite different when we draw connections between neighbors in the grid. The behaviour is still the same. This means that the nodes are still acting independently of each other.

## Averages

There are probably plenty of ways to make interesting things with this system of independent nodes. However, we will move on and try to make a connected system of some kind.

The obvious way is to utilize the links introduced in the previous section somehow. You could, for instance, make the connections into springs. That way they would basically try to keep a particular distance from their four (two/three if they are on the boundary.) neighbors.

Instead of making springs, let's try something else. In the following
animation we let all nodes move towards the *average position* of
their neighbours. In addition we apply a bit of noise to this motion. The
noise is the same random walk as before, but scaled down a little, so as
not to compete too heavily with the interaction we just introduced.

The cyan line indicates the position
of each nodes' *average position*.

This shows some promise. However, if we watch this for a while, it will simply eventually collapse into the center. You can take my word for at and read on, but it should not take too long for it to possible to see that this happens.

## Random Averages

To keep things from simply collapsing, here is a different strategy.

We introduce a new concept of randomized averages. (If you are mathematically inclined, this is my name for a linear combination where the weights are randomised.) We give each node a weight between zero and one. Now we use this weight to calculate the average position introduced in the previous section.

In addition we let nodes be either closed (●) or open (๐). The closed nodes will move towards the average position, as before. The open nodes will move away from the average position. The size of the circle denotes the magnitude of the node's weight. Intuitively this means that for two neighboring nodes, with circles of approximately the same size, the average position will be close to the middle of the two nodes. However, if the circles are of unequal size, the average position will be closer to the node with the larger circle.

All nodes are connected to at least two other nodes, so the total effect of this is a little complex to predict. But you can see what happens below

## Paths

Instead of displaying nodes and connections, we now draw the path of each node as it moves through time. This quickly becomes a little chaotic, but it does have some interesting tendencies.

## Strokes

A different way of displaying the behaviour is by drawing strokes between each node and it's neighbors. The strokes are drawn by sampling (a constant) number of random points between neighboring nodes for each iteration, and drawing a transparent dot at each position. (You can read more about this method at complexification.net.)

This also breaks down into disarray eventually, but until that happens it does display a neat kind of ordered chaos.

## Random Positions

Just to see what happens, here is the exact same structure as before with nodes initially distributed at random along the circumference of a circle. Now the initial position of a node is completely unrelated to it's neighbors. We can see this since the strokes between neighbors will begin to materialize at random.

## End

These were a few more techniques involving structures and random numbers that you can use to generate interesting results. Maybe you can find a way to apply this to a project of your own.

You can read the next part post in this series at Shepherding Random Growth.

You may also be interested in my illustrated essay On Generative Algorithms.