Reply To: Pseudo-randomising stimulus presentation

PennController for IBEX Forums Support Pseudo-randomising stimulus presentation Reply To: Pseudo-randomising stimulus presentation


Hi Zoë,

I answered a similar question on the original Ibex forums:

You should upload a .js file to the Controllers folder that contains the following code:

function RandomizeNoMoreThan(predicate,n) {
    this.args = [predicate]; = function(arrays) {
        let moreThanN = true;
        let order;
        while (moreThanN){
            order = randomize(predicate).run(arrays);
            moreThanN = false;
            let previousType = "";
            let current_n = 0;
            for (let i = 0; i < order.length; i++){
                let currentType = order[i][0].type;
                if (currentType != previousType){
                    current_n = 1;
                    previousType = currentType;
                    if (current_n > n){
                        moreThanN = true;
        return order;
function randomizeNoMoreThan(predicate, n) {
    return new RandomizeNoMoreThan(predicate,n);

Then in your main script you can do this:

Sequence("intro", randomizeNoMoreThan(anyOf("1A", "1B", "1C", "2A", "2B", "2C"),2), "exit")

Be very careful with it though, as it will freeze in an infinite loop if you don’t have enough items with each label to consistently break series of N items sharing the same label. For example, if you have 90 “1A” items but only a total of 10 items across the other labels, there is no way of avoiding series of more-than-two “1A” items and so your experiment would end up crashing.