Download Project File

How To Create A Random Word Cycle in After Effects

In this post, you will learn how to create a random word cycle in After Effects

Alright, so we are in After Effects and let me show you what we are going to be creating today.

We are in After Effects

So I have a text layer that has a bunch of different words that I am going to cycle through in my composition.

Let me show you what I am talking about. If I hit play, you will see random words cycle through in my composition like this.

I also have the option to control the Frame Rate, so if I select my text layer, I can then go to the slider inside of Frame Rate and take it down to maybe 2 frames.

Select text in After Effects timeline

In other words, it is going to shuffle through 2 of the words in 1 second. So it is going to slow it down for us so the words do not change as quickly

We can also speed it up by changing the slider Frame Rate to 8 frames instead of 2. That will make it go pretty fast.

8 frame rate slider in After Effects

Now let me show you how to set this up.

So the first thing I want to do is go inside of my text layer, select the Source Text and hit S twice on the keyboard to solo it.

Solo source text in After Effects

Then I will click on the stopwatch icon to create an expression.

Click on stopwatch icon in After Effects to activate Expression

Then I am going to create some variables.

Create After Effects Expressions inside a white text field

So the first one is going to be word = thisLayer because I want to grab words from my text layer. If I let go, you will see words in my composition.

Words text layer in After Effects

Now I want to split every single word into its own separate index and to do that I am going to use the Split Function.

So I am going to keep going with my code and I will say the following:

word = thisLayer.name.split(” “)

If we let go, you will see that it will split every single word into its own separate index.

Split Method in After Effects Expressions

Next, I want to know the number of words that we have, so I am going to add a new variable called wordCount = and I will say words.length;.

word = thisLayer.name.split(” “)’
wordCount = words.length;

WordCount in After Effects Expressions

So basically it is going to take the name of my text layer and then they will give me the number of words that I have in there. That is what the length is for. Now let’s see what happens!

Word length in After Effects Expressions

So right now it tells me we have 8 words. That is exactly what I have in my text layer title. If the number of words
changes, let’s say if I have 6 words, then it is going to give me 6 and so on. That is very useful.

I am going to keep going and now we are going to generate a random number. So I am going to say:

randomNumber = random();

Inside random(), I am going to say give me a random number between 0 and wordCount, which is we now know is 8.

word = thisLayer.name.split(” “)’
wordCount = words.length;
randomNumber = random(0, wordCount);

If you let go, it is going to give me a number between 0 and 8.

Random numbe between 0 and 8 in After Effects Expressions

I do not want all these decimals that you can see in the picture above. Let me show you how to get rid of them.

Let’s go to the next line and create a variable called roundedNumber and here we are going to round it downwards. So I am going to say Math.floor() and I will add a randomNumber().

word = thisLayer.name.split(” “)’
wordCount = words.length;
randomNumber = random(0, wordCount);
roundedNumber = Math.floor(randomNumber);

roundedNumber in After Effects Math Floor Expressions

Now it looks clean so we can actually do something with this number. Let continue with our code. In a new line, I am going to type words[] and instead of typing a number inside of the square brackets, I am just going to add roundedNumber. If I let go, you can see that now it kind of cycles through all of them really fast.

word = thisLayer.name.split(” “)’
wordCount = words.length;
randomNumber = random(0, wordCount);
roundedNumber = Math.floor(randomNumber);
words[roundedNumber]

Words RoundedNumber in After Effects Expressions

I am not done yet, I am going to keep going with this. I am going to add a seedRandom between wordCount = words.length; and randomNumber = random(0, wordCount);.

To do that, we are going to go into our Expression HelperRandom Numbers and click on seedRandom(seed, timeless – false).

seedRandom in After Effects Expressions

When you do that, it is going to add it into your expression like so:

word = thisLayer.name.split(” “)’
wordCount = words.length;
seedRandom(seed, timeless – false)
randomNumber = random(0, wordCount);
roundedNumber = Math.floor(randomNumber);
words[roundedNumber]

seedRandom in After Effects

Now we are going to change some things. Where it says seed, I am going to type time * 5 and I am going to change timeless from false to true.

word = thisLayer.name.split(” “)’
wordCount = words.length;
seedRandom(time * 5, timeless – true)
randomNumber = random(0, wordCount);
roundedNumber = Math.floor(randomNumber);
words[roundedNumber]

seedRandom Expressions in After Effects

So if you say false then it is going to give you a random value for each frame but when you say true, it is going to give you just one value but the seed generates a different value, so that is why we are going to animate the seed instead of timeless.

If I let go, you will notice that the words are still changing fast because we have those decimals. So we have to round our number downwards to get rid of it.

To do that, I am going to add Math.floor() and I will put time * 5 in my parenthesis.

word = thisLayer.name.split(” “)’
wordCount = words.length;
seedRandom(Math.floor(time * 5), timeless – true)
randomNumber = random(0, wordCount);
roundedNumber = Math.floor(randomNumber);
words[roundedNumber]

If we let go, you will notice that the numbers are changing a lot slower. So I can actually play with this number 5 or I can give it a variable instead of 5.

I am going to change it to frameRate and I will give it a value by saying frameRate, you are going to be 5.

word = thisLayer.name.split(” “)’
wordCount = words.length;
frameRate = 5;
seedRandom(Math.floor(time * frameRate), timeless – true)
randomNumber = random(0, wordCount);
roundedNumber = Math.floor(randomNumber);
words[roundedNumber]

So essentially, it is the same thing. We just put it inside a variable.

Inside a variable in After Effects

Now instead of manually changing the value in our code, let’s go to our text layer and then add a slider by right-clicking on the Effect Controls PanelExpression ControlsSlider Control.

Slider Control in After Effects

Let’s change the Slider Control to Frame Rate.

Change the slider to Frame Rate in After Effects Controls

Then instead of having 5 in the code, I am going to select the 5 and then pick whip to my slider.

Select and Pick Whip in After Effects

Pick whip in After Effects

So now I have the same thing except now I can control my value with the slider instead of just manually adjusting it in code. I can speed it up, slow it down and I can also add keyframes.

I hope you found this post useful. If you would like to learn more about Expression and how it can speed up your workflow in After Effects, check out my Learn After Effects Expressions Course.

Download Project File

About the author:

Sergei Prokhnevskiy

Sergei Prokhnevskiy is a Charlotte, NC based motion graphics designer, an online tutor, an entrepreneur, and Adobe MAX Master Speaker. Sergei is known for his quick and practical After Effects tips and tricks on YouTube, where he generated well over 6 million views on his tutorials. He has authored an online video course on After Effects Expressions and developed scripts for After Effects. He is also a former senior motion graphics designer at Fox Sports where he worked on graphics for NFL, Super Bowl, MLB, World Series, College Football, NASCAR, Women’s World Cup, and NASCAR Race Hub. He is very passionate about learning and teaching others.

5 FREE TIME-SAVING TOOLS

Over 100,000 downloads & counting!

These 5 After Effects tools will seriously speed up your workflow and save you hours of wasted time. More than that, they could be the difference between being able to complete a project on time or not!