PennController for IBEX › Forums › Support › Can we randomize time with newTimer() ? › Reply To: Can we randomize time with newTimer() ?
If you’re referring to the code from this message, it’s not a full code: it’s a streamlined excerpt of your code to which I added the relevant bits to use the Var method
timerd1duration that will store the generated random value (which, in the code from my message, I use when creating the Timer element named timer-D1 and when calculating the duration of the last Timer element). I took
getText("D1").remove() directly from your code, it’s your call to keep it or not, depending on what you want to happen at that time in the trial
If you use
newTimer("timer-D1",400+Math.round(1600*Math.random())) then there’s no point in using
timerd1duration = 400+Math.round(1200*Math.random()). You also will get a duration between 400ms and 2000ms (because 400+1600=2000).
"timer-D1" is a string (as you can tell by the double quotes) so you don’t want to include that in an arithmetic operation