?
Solved

After Effects Random Number, but different each time

Posted on 2016-10-04
5
Medium Priority
?
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

Introduction When sharing photos, especially via e-mail, the large resolution images that most cameras take today make for extremely large file sizes. The time required to upload these files to forums, send in e-mails, post to blogs or even placi…
Read about why website design really matters in today's demanding market.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Suggested Courses

752 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