Python 2.7,pyqt4
我知道
void run(void) { some_resource global_resource; global_resource.create(); vector<thread> my_threads; my_threads.reserve(thread_count); for(int i = 0; i < thread_count; i++) my_threads.push_back( thread([&global_resource](int i) { another_resource local_resource; local_resource.create(); // SIGTERM can happen here: work_with_resources(global_resource, local_resource, i); local_resource.destroy(); }, i) ); for(int i = 0; i < thread_count; i++) my_threads[i].join(); global_resource.destroy(); }
生成当前时间
但我如何获得随机hh / mm导入? 谢谢!
答案 0 :(得分:0)
您可以使用qrand()
生成随机秒数:
now = QtCore.QTime.currentTime()
QtCore.qsrand(now.msec())
time = QtCore.QTime(0, 0, 0).addSecs(QtCore.qrand() % (60*60*24))
print(time.toString("hh:mm"))
答案 1 :(得分:0)
一天有60×60×24秒,所以选择1到86400范围内的整数并将其添加到初始化为午夜的QTime
:
>>> from random import randint
>>> QtCore.QTime(0, 0).addSecs(randint(1, 86400))
PyQt4.QtCore.QTime(1, 23, 13)