Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Automatically generate different timeless random numbers in duplicate effects on the same layer

Contributor ,
May 12, 2020 May 12, 2020

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!

TOPICS
Expressions
5.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 12, 2020 May 12, 2020

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:

Screenshot_2020-05-12 09.44.45_vNMjBC.pngexpand image

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. 

Translate
Community Expert ,
May 12, 2020 May 12, 2020

It should work. Have you tried it? If it doesn't work for you, what's the effect and the property?

 

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2020 May 12, 2020

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:

Screenshot_2020-05-12 09.44.45_vNMjBC.pngexpand image

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 12, 2020 May 12, 2020

Strange. I was testing it with a text layer and got the following:

Annotation 2020-05-12 140718.jpgexpand image

 

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2020 May 12, 2020

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2022 Dec 19, 2022

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2022 Dec 19, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2022 Dec 19, 2022

Thank you Dan for thinking along with me, literaly outside the (afx) box.

I'll take a look at this idea, it sounds plausible.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2022 Dec 19, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2022 Dec 19, 2022

Oh That is superb Dan!

Its super late here now but will test this in the morning. Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 20, 2022 Dec 20, 2022
LATEST

Yes this works Dan! Thank you so much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines