Reply To: Pseudo-randomising stimulus presentation

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

#5250
Jeremy
Keymaster

Hi Zoë,

I answered a similar question on the original Ibex forums: https://groups.google.com/d/msg/ibexexperiments/1987FoZKo6k/XAw_XoX3AQAJ

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

function RandomizeNoMoreThan(predicate,n) {
    this.args = [predicate];
    this.run = 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;
                }
                else{
                    current_n++;
                    if (current_n > n){
                        moreThanN = true;
                        break;
                    }
                }
            }
        }
        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.

Jeremy