#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

# [open] Random order to variables without returning

edited April 2013

Hello, I'm trying to find the suitable way to use if conditions for what I want to do. but the following link isn't helping so I need help.
http://osdoc.cogsci.nl/usage/variables-and-conditional-qifq-statements/

After I set variables to the experiment, I assigned "random" to the order, but I need it to be random without return. For example, if a certain variable contains 1-10 numbers, and I have 7 cycles, I wouldn't want any number to appear twice, as there is an option to have 7 nembers appear without any of them repeating.
(like drawing items from a sac without returning them to it).

Thank you!

• edited 11:34AM

The loop item does random sampling without replacement. For example, if you have a loop table like this ...

... every number between 1 and 10 will appear exactly once. If this is not what you have in mind, could you please be a bit more specific about what you want to accomplish, and what you are doing at the moment?

Cheers!
Sebastiaan

• edited 11:34AM

yes I didn't explain myself correctly, assume I have two variables:
shape and color, each has 8 values, and the loop in which it is has to repeat itself 7 times.
my problem is: the same shape appears twice in these 7 cycles, which I don't want.
I need each shape (and color) to appear only once during these 7 cycles.
how can I use an "if" condition in order to do that?

Thanks,
Nagham

• edited 11:34AM

Ah, I see. This is not possible using only the loop item, but you can do it with a simple inline script. First, you use the loop table to define the eight shapes, as you would normally. Then, you create a list of eight colors in an inline script before the block_loop (as first item of the block_sequence, say).

``````# First create a randomly ordered list of colors
from random import shuffle
exp.colors = ['blue', 'red', 'green', 'purple', 'yellow', 'pink', 'brown', 'magenta']
shuffle(exp.colors)
``````

Then at the start of the trial_sequence, you `pop()` the last color from this list, and set it as an experimental variable, like so:

``````# This script should be in the prepare phase!
# Select the last color from the list and store it as [color]
exp.set('color', exp.colors.pop())
``````