# Exposition time randomization

I have a problem with my experiment. My goal is to randomize time exposition of stimulus from range 400-1600 ms with 200 ms intervals. As I understand there are two ways. First is to make a random generator for this range. Second is to make a list (every duration will be used 5 times) and a random choice from this list. My problem is to code this. As I wrote, I want to randomize duration for every stimulus but after all, there should be 5 x 400 ms, 5 x 600 ms …

``````# set up:
from numpy.random import shuffle

durations = [0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6] * 5
shuffle(durations)

# on each trial:
current_duration = durations.pop()
``````

Make sure to save the duration on each trial to your data file as well.

Thanks for the help I have one question more. This solve consist constant output of current_duration because I have to (I suppose) implement only object like current_duration inside the trial code. If I try to implement there durations.pop() then I have an error.

You need to state what the error is (I’m not sure I understand the problem, the error message should presumably help).

Of course, my mistake There is :
SyntaxError: can’t assign to operator
I assume there are basic questions but it’s my first project at all.

I have also a problem with randomization of blocks.

I have 3 affect conditions and I want to randomize, which one will be displayed.

Please provide the entire text of the error message. Currently we only know the generic problem, not in what line of code it occurs.

There is :

``````frameRemains = 1 + time = durations.pop() - win.monitorFramePeriod * 0.75
^
``````

SyntaxError: can’t assign to operator

I suppose this double definition (frameRemains = 1 + time = durations.pop()) is a problem but it also won’t work when I try this :

``````frameRemains = 1 + durations.pop() - win.monitorFramePeriod * 0.75  # most of one frame period left
``````

IndexError: pop from empty list

Are you editing a Builder-generated script manually? This is a challenge for experienced Python programmers and isn’t something that someone unfamiliar with programming should attempt (or generally, even need to attempt).

i.e. you posted this as a coding question and so I assumed you were writing your own script rather than using Builder. If you can’t see the reason for the fundamental error in this line of code:

``````frameRemains = 1 + time = durations.pop() - win.monitorFramePeriod * 0.75
``````

then I would highly advise against getting your hands dirty with the code (hint: there can only be one equals sign in an assignment).

You should stick to working entirely within the Builder graphical interface.

Lastly, you shouldn’t be popping elements from the list repeatedly. As in the code suggested above, you just do it once, and assign it to a variable name (i.e. `current_duration`). You can only pop an item from a list once. That decreases the list size by one. Therefore the total number of pops can’t exceed the number of items in the list.

Problem solved I know it is not especially resonable way to make experimental procedure (diving into code after builder) but now I have to deal with it. Of course I am gratefull for your help Michael. Now I have more advanced problem (I suppose) but for better clarity I will make a new topic.

I’m not saying that you shouldn’t attempt to insert custom code, but do this within Builder (which provides graphical “code components” from the component panel. That way, it takes care of inserting your custom code in the right place, which limits the error that can occur (and makes it much easier for us to offer help).