Nested Loop with a random subset of conditions

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): v2021.2.3
What are you trying to achieve?:

I am trying to build a nested loop. The outer loop is randomly referring to different condition files. In the inner loop, one of these condition files should be picked, but only one line in the Excel file should be picked randomly. Afterwards the outer loop should pick another condition file where again one line in the Excel file is picked presented and so on.

What did you try to make it work?:
I created the described loop structure, my outer loop refers to 144 different Excel files. Each of these Excel files has 9 conditions with 9 parameters. I tried to insert $random(1)*9 in the random seed box in the loop porperties to pick just 1 out of the 9 lines.

What specifically went wrong when you tried that?:
Whenever I am trying to start the experiment, I get the following error message:

Traceback (most recent call last):
File “C:\Users\ro-hu\Two_Faces_III\Two_faces_III_lastrun.py”, line 117, in
seed=random(1)*9, name=‘trials’)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 178, in init
self.sequenceIndices = self._createSequence()
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 265, in _createSequence
rng = np.random.default_rng(seed=self.seed)
File “_generator.pyx”, line 4412, in numpy.random._generator.default_rng
File “_pcg64.pyx”, line 109, in numpy.random._pcg64.PCG64.init
File “_bit_generator.pyx”, line 517, in numpy.random._bit_generator.BitGenerator.init
File “_bit_generator.pyx”, line 316, in numpy.random._bit_generator.SeedSequence.init
File “_bit_generator.pyx”, line 390, in numpy.random._bit_generator.SeedSequence.get_assembled_entropy
File “_bit_generator.pyx”, line 155, in numpy.random._bit_generator._coerce_to_uint32_array
File “_bit_generator.pyx”, line 149, in numpy.random._bit_generator._coerce_to_uint32_array
TypeError: seed must be integer

I hope you can help me, if you need additional information please let me know!

Hello,

if I understand you correctly, you simply want to select randomly one of nine rows in your excel-file? If so, use the Selected row property instead the the random seed. random seed only gives you a fixed random sequence of your nine rows.

If you want a random integer including 0 and 9 use randint(0,9).

Best wishes Jens

Hello,

I just tried out the the randint-function. Please test it thoroughly. In the few test runs so far, I do not seem to get what I would expect.

I tried randint(1,2) and expect to get 1’s and 2’s but so far I got only 1’s. Well, it might be that I did not do enough test runs.

Best wishes

Hello,

ok, it is randint(0,10) not randint(0,9). The latter only gives integers between 0 and 8. Nonetheless, please test it properly.

Best wishes Jens

Hi Jens,

thank you for your comments! Actually it seems like my biggest mistake was to insert it into the random seed property instead of the selected rows which you suggested. When I insert $random(1)*9 in the selected rows properties, it seems to be working fine. I hope it will also do so when I upload it to pavlovia.

Thank you for your help and excuse me for abusing this forum for my simple beginner’s mistakes. :slight_smile: