PDA

View Full Version : Randomly Choosing a WaitTime


new_horizon
06-29-2011, 04:36 AM
Hi All,

I am working on a program at the moment that requires an event to occur for 0.25s, but the timing of that event to occur at some point within a 1 second time frame.

I have tried setting up a new variable

probetime = random.choice([0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75])

and then using the following line...

yield viztask.waitTime(probetime) # wait before probe motion begins

The error message I receive is...

probetime = random.choice([0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75])
AttributeError: 'module' object has no attribute 'choice'

Am I trying to use the wrong commands here? I have used random.choice when dealing with speed in the past, but never time.

Thanks

Jeff
06-29-2011, 04:04 PM
You can use the random.choice command:
import viz
import viztask
import random

viz.go()

def MyTask():

while True:
randomTime = random.choice([0.25,0.5,0.75])
yield viztask.waitTime(randomTime)
print randomTime,'seconds elapsed'

viztask.schedule( MyTask() )