The Random Component in Grasshopper – A Beginner’s Guide

Random in Grasshopper - Featured Image
Quick links

Have you ever watched leaves scatter randomly on a windy day or admired the spontaneous pattern of raindrops on a window? Nature has a way of introducing chaos that results in beauty. In the world of digital design, harnessing such randomness can add depth, spontaneity, and uniqueness to our creations.

Enter the Random component in Grasshopper, a command that brings the serendipity of nature into the precision of design, allowing us to sprinkle in unpredictability to our well-structured digital worlds.

Curious about how this magical component can elevate your designs? Let’s dive in!

Adding the Random component

Let’s start with the basics – adding the component to your Grasshopper script. Find the ‘Random’ component in the ‘Sets‘ component tab, in the ‘Sequence‘ group. Select it and click anywhere on the canvas to add it to your script.

How to add the Random component in Grasshopper Component Tabs

If you prefer to use the component search bar, simply double-click on the Grasshopper canvas where you want the component to be placed, and type “random” into the search bar. Then click on the first result to add the component.

How to Add the Random Component in Grasshopper

Inputs and Outputs explained

The Random component in Grasshopper generates a sequence of randomized numbers. There are three ways we can influence these numbers, as controlled by the three inputs:

The Range (R) input controls the numerical domain the generated numbers should be in.

The Number (N) specifies the number of random values to generate within that domain.

And the Seed (S) controls the “starting point” of the randomly generated numbers.

By default, the Random component comes with a predefined Range of 0 to 1.00, and a number of values to generate of 1. In the example below we get the random number 0.771094.

Inputs and Outputs of the Random Component in Grasshopper

The generated numbers aren’t truly random because generating genuine randomness computationally is impossible. In programming the kind of output we are ‘pseudo-random’ numbers. In practical terms, the random numbers we get are randomized, but still quite evenly distributed. Which is actually a good thing for most design applications!

Controlling the Range of Random Numbers

The Range of random numbers is controlled using a ‘Domain’. In Grasshopper, a domain is defined by two values: the minimum and maximum value. To create a domain, use the ‘Construct Domain’ component located under the ‘Maths’ tab in the section titled ‘Domain’.

How to add the Construct Domain component in Grasshopper

The component has two inputs: the Domain Start (A) and Domain End (B) values of the domain. These represent the minimum and maximum values of a numerical range. In Grasshopper, its output, representing a domain, appears as:

0.3 To 1.5
Example of the Construct Domain component

Note: A domain is its own datatype in Grasshopper – we can’t just feed two numbers into an input that requires a domain. It needs to be constructed with the ‘Construct Domain’ component.

You can input any numerical values, not just whole numbers, into the Start and End inputs.

Once connected to the ‘Range (R)‘ input of the Random component, the domain controls the range the randomly generated number(s) must fall within. In the example below, the Number (N) of values to be generated is still at the default of ‘1’.

Example of Random Component Range

The Seed input explained

To generate the numbers, the Random component takes the ‘Seed (S)’ input (which is simply a number), and then runs an algorithm that generates a set of randomized numbers within the defined domain. The Seed is the starting point – hence the name.

Why control the Seed? Well, in most cases, we don’t need to. But it comes in handy when we aren’t happy with a set of random values: we can add a number slider and change the ‘Seed’ number, to get a different set of random values.

In addition, the Seed input is also a powerful tool to control how many sets of random numbers to create. For instance, sometimes we want multiple sets of random numbers within a domain, not just one. Adding several seed numbers and grafting the input, will result in several lists, all with different sets of random values. Quite handy!

Now let’s see how to use this component in an example!

Application Example

The Random component is a powerful tool to create variation within a field of objects. Here’s an example of how you might use the Random component:

Imagine we want to create the following effect: We want to generate circles of randomized sizes in a grid. The parameter we’ll want to define is the range of the largest and smallest circle.

Example of the Random component

Script setup

The basic setup is as follows. I referenced a surface modelled in Rhino to a Surface container component. In the example the surface is 30 units high, and 45 units wide. The surface is then ‘divided’ with the ‘Divide Surface’ component, which generates a grid of points on the surface. The number of points in the U and V direction can be controlled by a number input in the U and V inputs. For this example I’m sticking with the default value of 10 for both.

The Points (P) output contains the grid of points, organized in lists by row. Next I added a ‘Circle’ component, which asks for the center point of the circle, and a radius. The grid points will be the center points, and for now the output shows circles with the default radius of 1.

Finally I turned the closed planar curves into a surface, by connecting it to a surface data container (to get a shaded circle).

Example Random component in Grasshopper Step 1

Using the Random Component to Generate Variation in Grasshopper

Now let’s add the Random component to introduce some variation in the size of the circles.

We’ll also add a ‘Construct Domain‘ component to define our minimum and maximum values for the radius, which we’ll control with two Number Sliders. We’ll connect this domain to the ‘Range (R)’ input of the Random component.

At this stage we are generating a single random value within the Domain we specified. As a result, all the circles are still the same size: they share the same radius of 1.225313.

Example of the Random component Step 2

Creating the Right Amount of Random Values

To generate as many random radius values as we have circles, we need to first get the number of points we have in our grid. Let’s use the ‘List Length‘ component and get the list length of the Points (P) output. And connect it to the Number of Steps (N) input of the Range component.

The output doesn’t quite show what we wanted: we are getting random circle sizes, but the same values repeat for each list in the grid’s point output.

Why is that?

The reason is that the List Length component returns the length of every one of the lists in the Point (P) output (a length of 11). Since these identical lengths are stored in separate lists, we are asking the Random component to generate 11 values within the Range we specified, but here is the crucial part: using the same Seed (S) input. This means that for every one of the 11 random values, the same starting point is used, leading to the same output.

Example of the Random component Step 3

There is two ways to fix that: we can either generate as many different Seed (S) input numbers as we have lists, or we combine all the points in a single list, that way one Seed (S) value will be enough.

In this example, it’s easier to combine the points into a single list. To do so, right-click on the Point (P) output of the Divide Surface component, and click on ‘Flatten’.

Example of the Random component Step 4

Once the point list is flattened, the List Length component returns the total number of points, which in turns gives the Random component the instruction to create 121 random values.

We’ve successfully implemented the Random component to create variation!

Example of the Random component Step 5

The Random Component in Grasshopper – Final thoughts

Embracing randomness, as we’ve discovered, can be the breath of fresh air that revitalizes our digital designs. The Random component in Grasshopper allows us to elevate our designs by introducing a controlled unpredictability, mirroring patterns in nature.

If you’ve found this article helpful and you’re eager to dive deeper, our Grasshopper Pro online course is the perfect next step. Fast-track your learnings and harness the full power of Grasshopper, tailored especially for architects ready to elevate their designs. Join us, and let’s create wonders together!

Happy designing!

Like this article?
Share on LinkedIn
Picture of Thomas Tait
Thomas Tait
Architect at Snøhetta and Head Instructor @ Hopific (or, in plain English, I help designers use Grasshopper to supercharge their designs.
Ready to Dive into Grasshopper? Grab Your Free Ebook!

Accelerate Your Learning and Get Up and Running Quickly.