The Expressions Cheat Sheet
Loading...

random() gives you a random number between 0 and 1

random() // anywhere between 0 and 1. Updates every frame

Random Rotation

Apply this to a Rotation property:

random()

It might not be very obvious, but if you look closely you can see the image is rotating ever so slightly.
The image gets a new random rotation between 0 to 1 degree, which is very little.

Fortunately for us, we can give random a multiplier!

random(360)

Now our Rotation property will be randomly set to anywhere between 0 and 360 every frame. Cool, fuzzy but cool.
Let's tone it down a notch:

random(10);

This is cool, but it almost feels like something is wrong. Oh, I know! Our layer is only leaning to the right. That's because random(10) gives us a number between 0 and 10.
Fortunately for us (we are very lucky today), random is very kind. If we give it two numbers instead of one, it treats them as a range.

random(-10,10);

That should do the trick. Now the layer should rotate 10 degrees to either direction.

Move in random directions

the Position property usually expects two values in an Array. This should do the trick:

var max = 50;
var randomX = random(-max, max);
var randomY = random(-max, max);
value + [randomX, randomY];

Now we can easily specify what is the maximum amount of randomness we want to add to the original value.
The result is very similar to wiggle(), the difference is that wiggle tends to be smoother and transition between new values slowly and across multiple frames.
Random as mentioned before gives you a completely new value every frame, resulting in a much sharper, more brutal transition.

Random Color (Warning: flashing lights)

A color in expressions is usually represented by an array of normalized values (0 to 1), a value for each color channel (Red, Green, Blue, Alpha).
Although alpha is many times ignored in most color properties, for some reason it might be required.

Either way, to create a new random color every frame we can use the expression below:

[random(), random(), random(), 1];

random() is serving us well here because a value between 0 and 1 is exactly what we need.
Uncheck "Pause" to see the color value changing randomly (warning: flashing lights):