Question:How to realize the randomization of the selection

I would like to ask a question. If I make an XLSX table and have two routine (50 items), how can I make the first routine refer to 10 items in XLSX randomly, and the second routine immediately refer to 10 items in 11 the remaining 40 items?
Thank you for your help.

Builder loops don’t work like that. They read from a conditions file one row at a time, and all routines within the loop only have access to the values in the current row.

To achieve what you want, you would need to disconnect the conditions file from the loop and just give the loop an nReps value of 10. You would then need to use some custom Python code in a code component that would read in the .xlsx file, select 10 rows to be used for the first routine, and 10 others to be used for the second routine. On each iteration of the loop, you would need to refer to the current values from each of those two separate lists of rows.

It’s possible that I misunderstood your description though, and that you actually want 10 reps of the first routine, followed by 10 reps of the second. That would be doable by putting a separate loop around each, connected to the same conditions file. You would just need to specify a selection of ten rows in the “selected” rows field of each loop, ensuring that the two selections don’t overlap. If that’s what you’re after, it would require only a tiny bit of custom code before hand, and I’d be happy to help with that.

I’m very grateful to you for your reply.Then,my expression may not be accurate, but it is the third paragraph of your understanding, if you would like to help me solve the code problems, I will be deeply grateful to you.

OK, in your first component, insert a “code” component (from the “custom” component tab). In its “begin experiment” tab, put something like this:

row_selection = list(range(50))
shuffle(row_selection) # randomise it

Then in the first loop, in the “selected rows” field, put:


and in the second, put:


This will give you random, but non-overlapping, selections of 10 rows for each loop.

Words cannot express how grateful I am to you. Thank you very much indeed.