Solved

After Effects Random Number, but different each time

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
In this article, I'll explain how to change the color of a selection in Photoshop. I'm sure there are a couple different ways to do this in photoshop, but this is my preferred method in Photoshop. I am using Photoshop CS6 and I will be adjusting the…
The viewer will learn how to dynamically set the form action using jQuery.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

786 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