Selecting randomly different amounts of rows from two subsets of rows in a condition file

I am building my experiment in Builder view, but will run it online on Pavlovia. I use Psychopy version Standalone PsychoPy 2020.1.3 for 64bit Windows (using Python 3.6).

In my conditions’ file, I have two subsets of rows that must be intermixed in different proportions. For example, I have first 30 rows with stimuli that I am actually interested in, and 30 rows in the second half with stimuli from which I need to choose randomly only 7 items in each block. These stimuli will work as distractions for participants. I can’t only enter 37 rows in my condition file (30 rows for ‘real’ stimuli and 7 rows for distracting stimuli) and select a random order, since it is important to select the distractions randomly from a pool of 30 pictures in each block. Otherwise, each participant will only get 7 same distractions throughout experiment.

Distracting stimuli must be randomly intermixed with real stimuli, resulting in totally 37 shows from the condition file in one block. Condition file has 60 rows in total.

I am sorry if a topic answering this question was already created. I found similar ones, but didn’t see how the rows could be intermixed.

Thank you!

My solution involved a code component with JavaScript code for generating random numbers from two subsets:

  • numbers in a row from 0 to 27 (in my final experiment, I changed the rows, so this is instead of 30);
  • 7 numbers from the subsets of numbers from 28 to 55 (also changed).

I entered this code in the the beginning routine section. The code element was placed in the routine running just before each block.

I created a new variable including those generated numbers and added it in the ‘selected rows’ field in the loop which was randomized and intermixed there as well by selecting ‘loopType’ = random.

Works perfectly online.


The code:

let numbersInRow =
let randomNumbers = ;

for (let i = 0; i <= 27; i++) {
for (let i = 0; i < 8; i++) {

function randomize(randomNumbers) {
const randomNumber = Math.floor(Math.random() * 28) + 28;
if (randomNumbers.includes(randomNumber)) {
return randomize(randomNumbers);

return randomNumber;




I changed also from 7 to 8 rows from the second subset.

Do you have to convert array i.e the variable new_rows to strings to work in the end ? I am trying to present 55 items out of 110 items. I did something similar to you. Doesn’t work for me. Can you check please.