Set random seed for repetition of trials in Pavlovia

Hello everyone - I am trying to set the random seed for trials repetition in js. The seed is randomly generated but constant across repetitions so that the sequence of trials is random in the first block but then identical to the first block in all subsequent blocks.

In python this is really simple: I have a code component

sequence = random.randint(1,1000)

and then I set the random seed of trial repetitions to $sequence.

However, I can’t figure out how to do that in js! I have tried everything, looked at the sheet crib and all previous replies on a similar topics but couldn’t quite figure this out.
In js even though I have

var sequence;
sequence = Math.floor(Math.random() * 1000 + 1);

and then I set the random seed of trial repetitions to $sequence I get the error

  • ReferenceError: $sequence is not defined

Anyone has suggestions? Thanks!

Remove var sequence

You gotta be kidding me! It’s working as intended now…thanks very much!

Can you explain the logic behind so I understand what’s going on? Thanks a lot

This is actually something I’ve had a problem with this week with one of the PsychoPy 2023.1 release candidates.

My understanding is that if you specify var X in a code component then the scope of X is restricted to that code component tab.

Possibly what happens is that when PsychoPy compiles your JavaScript file, any variables that have not been given a restricted scope are defined at the experiment level.

However, I’m not a JavaScript programmer so this is based on my experiences with PsychoJS and the Python to JS transpiler.

I see, thanks very much for the interesting clarification.

You definitely saved me a lot of headaches! Thanks