Copy link to clipboard
Copied
If I want to automatically generate a different timeless random numbers on each instance of a duplicated layer, I know how to do that by referencing the index. For example:
seedRandom (index, true);
random ()
What I need to do is similar to that, but I need the different timeless random numbers to be generated in duplicated effects on the same layer.
Obviously, using 'index' won't produce different random numbers between the duplicated effects because the layer number will be the same for all instances of the effect. Instead, what I need is some way to either self-reference the effect name/number, or randomly generate a timeless number without specifying a seed. See what I mean?
Any suggestions?
Thanks!
1 Correct answer
I'm not exactly sure what you are trying to do but if you add this expression to the Transform Rectangle 1> Rotation property
seedRandom(index, timeless = true);
random(90, -90)
you get this when you duplicate the rectangle:
That looks like random values on the same layer to me.
If that doesn't work for you we need more workflow and design details.
Copy link to clipboard
Copied
It should work. Have you tried it? If it doesn't work for you, what's the effect and the property?
Dan
Copy link to clipboard
Copied
I'm not exactly sure what you are trying to do but if you add this expression to the Transform Rectangle 1> Rotation property
seedRandom(index, timeless = true);
random(90, -90)
you get this when you duplicate the rectangle:
That looks like random values on the same layer to me.
If that doesn't work for you we need more workflow and design details.
Copy link to clipboard
Copied
Strange. I was testing it with a text layer and got the following:
Strangely, while the index number remains 1 for all the effects applied to the top layer (as per the sliders), and you can only get a different random number by changing the seed between generators in the same expression, when you apply the same seed in a different effect you will get a different random number. I don't really understand why that is, but it works.
Thanks for your help.
Copy link to clipboard
Copied
A text layer only has one Source Text property so you need to change the seed every time you duplicate the random number generator. Pretty straight forward.
Copy link to clipboard
Copied
Hi Rick or Dan,
I have a followup question, maybe you can help here?
I am making something that has to change to a random number every time I open up after effects.
So each time I want a different result.
Right now what I did is drive the index number with a second slider, which makes use of Date.now.
This actually works, even the timess part. However its kinda unstable. Every property I change, wheter its a random key or turning something on or off in afx changes the index number because of the Date.now.
Also when opening the exact same file on mac instead of windows breaks the timeless part and I get every frame a new index number. See my code below.
My question, is there a more stable way to get a random number without using Date.now? Maybe someting that is only called when opening afx and then stays the same?
Code:
Slider 1: this is my code to generate me a number between 0 & 13:
seedRandom(effect("Slider")("Slider"),timeless=true);
Math.floor(random(13));
Slider 2 generating random index nr:
num1 = Date.now();
lastDigit1Str = String(num1).slice(-2);
lastDigit1Num = Number(lastDigit1Str);
Thank you
Copy link to clipboard
Copied
This is a pretty convoluted idea, so maybe someone will come up with something better, but you could create a simple script that writes out a CSV (or JSON) text file with a random number and put that script in the Scripts/Startup folder so that it runs whenever AE is launched. If you then import that file and make it part of your project, you could reference it from your expression to get a random seed that changes every time you run AE.
Copy link to clipboard
Copied
Thank you Dan for thinking along with me, literaly outside the (afx) box.
I'll take a look at this idea, it sounds plausible.
Copy link to clipboard
Copied
Curiosity got the best of me, so I tried it and it works. I added this simple script (which generates a 4-digit random integer) to the Scripts/Startup folder:
var myRandom = Math.floor(Math.random()*10000);
var myFile = new File("/c/test/random.csv");
myFile.open("w");
myFile.writeln("Random");
myFile.writeln(myRandom);
myFile.close();
Then I imported the csv into AE and used this expression to access the random seed:
seed = footage("random.csv").dataValue([0,0]);
seedRandom(seed,true);
// do random stuff
The result is different every time I launch AE.
Copy link to clipboard
Copied
Oh That is superb Dan!
Its super late here now but will test this in the morning. Thank you so much!
Copy link to clipboard
Copied
Yes this works Dan! Thank you so much.

