Solved

After Effects Random Number, but different each time

Posted on 2016-10-04
5
119 Views
Last Modified: 2016-10-06
I'm trying to create an expression for a slider control that will generate a random number between 1 and 8, but making sure the same number is not picked simultaneously two times in a row.

However, lastValue is always being read as 0.
Any idea what I am doing wrong?


holdTime = 0.1;
lastValue=thisLayer.effect("RandomNumber")("Slider").valueAtTime(time-holdTime)
seed = Math.floor(time/holdTime);
seedRandom(seed,true);
do
{
  newValue=Math.round(random(1,8));
} while (newValue==lastValue)
newValue
0
Comment
Question by:stuartlandreth
  • 3
5 Comments
 
LVL 29

Expert Comment

by:fibo
ID: 41829273
1 - I would think that valueattime is your problem
2 - your algorithm needs some revision: you do not need to reset seed each time, and in fact not sure what happens if you remove any seed call
0
 

Author Comment

by:stuartlandreth
ID: 41829632
Thanks for the comments. In the end, we dropped the random number generator and just used our own array of pre-defined "random" numbers where no two consecutive numbers were the same.
1
 
LVL 29

Accepted Solution

by:
fibo earned 500 total points
ID: 41831310
This was indeed your best option.
In case your prefdefined array is hard coded, you might add a salt of random by choosing randomly at which part of the sequence you start initially (assuming of course that at the end of the arry you loop back to the beginning)
0
 
LVL 29

Expert Comment

by:fibo
ID: 41831750
B-) Glad to have contributed. Thx for the grade and the points!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question