This example illustrates a method to be used to permit randomization with the constraint that no two consecutive trials present the same stimulus.
The trials are entered individually in the TrialList. A User-Defined Type (UDT) is created on the User tab of the Script window. This is used to keep all of the information about each trial (e.g. stimulus text, stimulus color, etc) organized under a single variable. In script, an array of the UDT is created, and each individual trial is loaded into the array. The array is then randomized, and a criterion is checked. This sample differs from the No Repeats on Consecutive Trials (Condition) sample in that the criterion is that no two trials with the same stimulus are presented, as opposed to no two trials of the same condition. In this case, the condition is "ignored". Two trials of type 1 can be presented consecutively, so long as the actual stimulus itself (e.g. text string) is not identical.
When adapting this sample to your own experiment, note that some lists of stimuli may not be easily randomized, especially if you have a very small number of choices. Occasionally it may not be possible to meet the constraints on the randomization. If the script in the experiment continues to try to randomize to meet those constraints and is unable to do so, the experiment may appear to freeze. The MAX_RETRY variable prevents the experiment from freezing by allowing the loop to exit after a certain number of retries. If the experiment fails because of too many retries, you can start the experiment over and try to randomize again. If the experiment fails very often, you may need to use pseudorandomization.