If you create a sequence that you want to use over and over, then you most likely do not want it to look like an identical copy running in lockstep with the others.  Rather than writing a slightly different sequence for each copy, it is easy to write one sequence containing randomness so that extra copies do not run in lockstep. Here are three ways to do that.

1. Random delay before start
Fine control of how much skew exists between copies
2. Random starting point
Course but precise control of initial skew (usually only a few choices)
3. Random repeat rate
Allows copies to drift in and out of lockstep

For best results, use #1 or #2 along with #3.

In order to see it, the same sequence should play independently on several LED Ports. Set Theme Designer as follows to see three copies operating independently, thus making their randomness visible:

Random Delay Before Start

Perform a random delay, then start the sequence normally. The eyeball estimate is that the start delay will loop about 50 times if 98% likely, or for around 1.25 seconds.

//Eat At Joe's with
//Random Delay Before Start
//Making Sequences: Add Random Timing

startDelay
@25ms go to startDelay with 98% chance

repeatLoop

@+0s Chn1 = 100%      //Eat... 
@+1s Chn2 = 100%      //At... 
@+1s Chn3 = 100%      //Joe's! 
                      //All stay on for 2 seconds 
@+2s Chn1 = 0%        //All turn off at same time 
     Chn2 = 0% 
     Chn3 = 0%        //All stay off for 1 second 
@5s                   //wait until 5 seconds and start over

     //don't fall through, skip start delay
     Go To RepeatLoop

Random Starting Point

Identify several points in a sequence that are suitable to start from when first powering up. Use Go To with Chance for each label.  If all the labels in a range are suitable starting points, it is easier to use one Go Between statement. Go Between was used in the following example.

//Eat At Joe's 
//With Random Start
//Start labels are moved to right side to
//keep left side uncluttered and easily readable
//Making Sequences: Add Random Timing

//equally likely 20% chance each starting point
 Go Between start1 and start5 //do this once

                                       //start labels
                                         start1
@+0s Chn1 = 100%                         start2 //Eat... 
@+1s Chn2 = 100% Chn1 = 100%             start3 //At... 
@+1s Chn3 = 100% Chn2 = 100% Chn1 = 100% start4 //Joe's! 
 //All on for 2s 
@+2s Chn1 = 0% //All off 
 Chn2 = 0% 
 Chn3 = 0%       //All stay off for 1 second 
@+0.5s                                   start5
@5s              //wait until 5 seconds and start over

     //cannot fall through and start randomly again
     Go To start1 //Repeat

Random Repeat Rate

The first two randomizations only vary the starting time. They keep the repeat rate constant. A good practice is to have the repeat rate vary by such a small amount as to appear constant. Over time, extra copies of the same sequence will drift ahead or behind one another.

//Eat At Joe's with
//Random Repeat Rate
//Making Sequences: Add Random Timing

@+0s Chn1 = 100%      //Eat... 
@+1s Chn2 = 100%      //At... 
@+1s Chn3 = 100%      //Joe's! 
                      //All stay on for 2 seconds 
@+2s Chn1 = 0%        //All off at same time 
     Chn2 = 0% 
     Chn3 = 0%            //All off for 1 second 
@5s                   //wait until 5 seconds and start over

     //add random delay before repeat
     go to passSkew with 50% chance
@+100ms 
passSkew

     //falls through and repeats

 Comparing approaches

1. Random delay before start
Best randomization of starting point. May require tweaking to get the right range of delay.
2. Random starting point
Can be more code to write. Can often result in the exact same timing for two copies running.
3. Random repeat rate
Best randomization long-term but takes so long before sequences drift apart.

 

What else can we say, except that was random.

 

Back to Menu