Problem with using random numbers in stimulus timings

OS (e.g. Win10): MAc OS 11.2.3
PsychoPy version (e.g. 1.84.x): 2021.1.2
Standard Standalone? (y/n) y
**What are you trying to achieve?:

I had an experiment in builder and on Pavlovia that I created last year, but it broke after updating to latest version. Even though I tried using older version, I cannot get it to run. So I re-created it from scratch, but now I get different errors.
Specifically, I need to display a stimulus for a random interval between 1200 and 1800ms

What did you try to make it work?:

I have the text stimulus and set its duration to $NC_Wait
I have a code component
NC_Wait =np.random.uniform(1.2,1.8)
I get this error message:
if tThisFlip > asarray($NC_Wait)-frameTolerance:
^
SyntaxError: invalid syntax

I tried taking away the $, using just random without np. and also leaving out the uniform.

Any ideas?

Hello,

the following psyexp-file shows how to implement a random stimulus duration.

RandFix.psyexp (6.5 KB)

I do not really see the need for a uniform distribution when you generate a random number for each trial. Anyway, if you want to use a uniform random number generation, change the line

stim_dur = 1.2+(1.8-1.2)*random()

to

stim_dur = np.random.uniform(1.2,1.8)

Notice, that random.uniform uses a half-open interval [low, high). The lower boundary is included, the upper boundary is excluded.

Best wishes Jens