Randomness in p5js

For my independent study project, I’ve ended up down a rabbit hole, exploring space colonizing algorithms. The starting point for most of these explorations is a random or pseudo-random assortment of points in space.

Random points!!!

I wanted to quickly run through three different techniques for achieving random-ish distributions of things in p5JS.

random()

This seems to be a direct port of the Math.random javascript function. The result is a random distribution across the entire specified range that is passed into the function. Technically this is a pseudo-random number and with a large enough data set, a pattern might begin to emerge.

randomGaussian()

Random gaussian produces a ‘normal’ distribution of values. I was never very good at stats, but imagine the numbers clustering around the middle or average, just like on a bell curve. Most of the lines will be in this middle chunk, however, there will be outliers. This function allows you to define both the mean(middle point) and standard deviation or how far away from the middle the lines will likely stray. I have found this function useful for moving from high to low densities of objects. This begins to look a little less chaotic than random().

noise()

Noise makes use of Perlin noise and results in a more natural-looking noise pattern. You can think of noise as a smoother version of gaussian noise