简体   繁体   English

如何使用 rng 值作为 time.sleep 的值

[英]How to use an rng value as value for time.sleep

I'm trying to make a simple timer that after the time restarts the whole body of code but list can't be used as value, is there any other alternative?我正在尝试制作一个简单的计时器,在时间重新启动整个代码体但列表不能用作值之后,还有其他选择吗?

randomlist = random.sample(range(200, 330),1)
time.sleep(x)

did you mean to so something like this:你的意思是这样的:

from time import sleep
from random import uniform

# sleep something between 2 and 5 seconds
sleep(uniform(2, 5))

time.sleep accepts a single float as number of seconds to sleep;time.sleep接受一个float作为睡眠的秒数;random.uniform provides just that.random.uniform提供了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM