| Reference | Downloads | Github

Independently select random parameters of conditions

I am building an experiment will participants will see two pictures in each trial–one from each of two separate categories, both selected at random.
I made an excel file for the conditions with a column for each of the picture categories but as it is, it always shows the same pictures in the same row together.
How do i make it so it randomly selects one from each column on each trial?

Hi Ashish,

Try using a code component. In the “Begin routine” tab of the component write:

Image1=np.random.choice( name of Column One in your conditions file)
Imaget2=np.random.choice( name of Column Two in your conditions file)

Then within your image components just set “Image” to be Image1 and Image2 respectively for each image.

Let me know if this is clear,

Hi Becca,

But Builder just gives us one value from each column on each trial. i.e. the name of column one represents only the value of the current row from that column, so we can’t make random choices from it.

In this situation, the usually recommended course is to put some code in a code component that runs at the start of the experiment. It reads in the .csv conditions file, shuffles the values within each column, and then saves out the .csv file back to disk. Builder then just uses that file in a loop like any other.

We really need to get a proper example of this code here in this forum, but meanwhile, here is an old thread that might be of use:!topic/psychopy-users/WljgXeoy6Ik