Solved

After Effects Random Number, but different each time

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In this tutorial viewers will learn how to create a Photoshop action to apply adjustments and effects to multiple images. Open a photo for editing in Photoshop: Open the Actions window by going to Window > Actions: Start a new action by selecting th…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now