Solved

After Effects Random Number, but different each time

Posted on 2016-10-04
5
141 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 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

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…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Users will learn how resize a batch of photos from a single command in Photoshop via Photoshop's Image Processor. Open up an Image you'd like to resize in Adobe Photoshop: Adjust the image size according to your preferences. Image > Adjustments > …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

707 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