WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Randomly Choosing a WaitTime (https://forum.worldviz.com/showthread.php?t=3821)

new_horizon 06-29-2011 04:36 AM

Randomly Choosing a WaitTime
 
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:
Code:

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() )



All times are GMT -7. The time now is 02:22 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC