How to randomize subset of trials without any trial in the subset repeating? #733
-
Hi! So I’m trying to randomize a subset of trials in my experiment (trials [2,4,7,10] in the code below), however I would like it to be that none of the trials repeat after they are run (which is what is happening now). So essentially what I want to happen in that the 3rd trial in the experiment could be either [2,4,7, or 10], but that once one of them is chosen, it won’t appear again in the 4th, 7th, or 10th trial. Does anyone know how I can do this? Thanks! Lauren Here is the code for reference: sample: { |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
You'll need some javascript. Is this what you're looking for? var samples = [2, 4, 7, 10]
function popOneOff() {
var rand_index = Math.round(Math.random() * (samples.length - 1))
var item = samples[rand_index];
samples.splice(rand_index, 1);
return item;
}
var x = {
type: "alternate-groups",
groups: [
[0],
[1],
[popOneOff()],
[3],
[popOneOff()],
[5],
[6],
[popOneOff()],
[8],
[9],
[popOneOff()],
[11]
],
randomize_group_order: false
}; |
Beta Was this translation helpful? Give feedback.
-
Thanks for your help! I'm actually not familiar with javascript, so I'm not really sure how to put this into my code. (I removed my original code I had and put the code you suggested in but it didn't seem to change anything). If it helps, these are the trails that I'm using in the experiment. The numbers I listed for groups correspond to these trials, the first one being 0. var test_procedure = { |
Beta Was this translation helpful? Give feedback.
-
Are you looking for something like this? var test_procedure = {
timeline: [likert_trial, multi_select, text_page],
sample: {
type: "custom",
fn: function(samples) {
function popOneOff() {
var rand_index = Math.round(Math.random() * (samples.length - 1));
var item = samples[rand_index];
samples.splice(rand_index, 1);
return item;
}
return [
0,
1,
popOneOff(),
3,
popOneOff(),
5,
6,
popOneOff(),
8,
9,
popOneOff(),
11
];
}
},
timeline_variables: [
{
audio: "sound/condition1/01.wav",
trans:
"Allie: When I was younger we had five kids in the " +
" house which would be my two- three older brothers and then my sister and I.",
stim: "1"
},
{
audio: "sound/condition1/02.wav",
trans:
"Courtney: Ah, that’s kind of unusual for me. Usually if I’m " +
" gonna drink a litre of anything it would be juice.",
stim: "2"
},
{
audio: "sound/condition1/03.wav",
trans:
"Reggie: Like we had to host games, like all the groomsmen " +
" there.",
stim: "3"
},
{
audio: "sound/condition1/04.wav",
trans:
"James: Basically, that’s the only move I made during my childhood " +
" was just from one house to the house next-door on Alexander.",
stim: "4"
},
{
audio: "sound/condition1/05.wav",
trans:
"Taylor: Yeah and it was a- like a school welding competition. " +
" We got smoked there, but. We had to build this big- ah for a pot, like a flower-pot. Just the cage.",
stim: "5"
},
{
audio: "sound/condition1/06.wav",
trans:
"Ryan: I think it was grade two actually. They had this Christmas advent calendar. " +
" It’s one of those calendars with the chocolate things for each day.",
stim: "6"
},
{
audio: "sound/condition1/07.wav",
trans:
"Mallory: And I did like- I was involved in the sports, " +
" I was involved in the bands, like, concert band, and.",
stim: "7"
},
{
audio: "sound/condition1/08.wav",
trans:
"Justin: The shop class is full of college students. Or " +
" university students and, ah, he’s sitting- he was white as a ghost." +
" He’s sitting in the chair at the bottom.",
stim: "8"
},
{
audio: "sound/condition1/09.wav",
trans:
"Katie: Stacey from- one of the managers. He’s like my " +
" favourite manager. Ever since that, anyway.",
stim: "9"
},
{
audio: "sound/condition1/10.wav",
trans:
"Mark: And I have, ah, one brother who’s a- about a year " +
" younger than me. Ah, a sister who’s about three years younger than me.",
stim: "10"
},
{
audio: "sound/condition1/11.wav",
trans:
"Brett: So, at the starting the night when we were still at " +
" the hotel, cause our hotel- the concert was at our hotel.",
stim: "11"
},
{
audio: "sound/condition1/12.wav",
trans:
"Kyle: My brother’s kinda just like laying about the house " +
" right now, waiting for college, I guess. He really doesn’t really " +
" seem to do much when he’s not at school.",
stim: "12"
}
]
};
timeline.push(test_procedure); |
Beta Was this translation helpful? Give feedback.
Are you looking for something like this?