Python:随机系统时间种子

Python:随机系统时间种子,python,random,time,Python,Random,Time,在python中,假设我在一个具有随机种子生成器的系统上,如何让random.seed()使用系统时间?(好像/dev/uradom不存在)您可以这样做 import random import time random.seed(time.time()) 你知道这个图书馆吗:PyRandLib?见: https://schmouk.github.io/PyRandLib/ to easily download archives versions, and https://github.com/

在python中,假设我在一个具有随机种子生成器的系统上,如何让random.seed()使用系统时间?(好像/dev/uradom不存在)

您可以这样做

import random
import time
random.seed(time.time())

你知道这个图书馆吗:PyRandLib?见:

https://schmouk.github.io/PyRandLib/ to easily download archives versions, and
https://github.com/schmouk/PyRandLib to get access to the code.
该库包含许多同类最佳的伪随机数生成器,同时与Python“内置”库random完全相同(只需在Python目录的“Lib/site packages/”子目录中解压缩或解压缩下载的存档文件)

从代码和模块“fastrand32.py”中,您将获得一种非常复杂的方法,用当前时间的混洗版本提供random。出于您的目的,这将成为:

import time
import random

t = int( time.time() * 1000.0 )
random.seed( ((t & 0xff000000) >> 24) +
             ((t & 0x00ff0000) >>  8) +
             ((t & 0x0000ff00) <<  8) +
             ((t & 0x000000ff) << 24)   )
导入时间
随机输入
t=int(time.time()*1000.0)
random.seed((t&0xff000000)>>24)+
((t&0x00ff0000)>>8)+

((t&0x0000ff00)来自该链接:“如果随机性源由操作系统提供,则使用它们来代替系统时间(有关可用性的详细信息,请参阅os.urandom()函数)。”这是我试图避免的。所以我不明白你的问题,你在找什么?你在找
random.seed(time.time())
?难道你不能使用类似于
random.seed(time.time()
)的东西吗?Python不是自动有一个随机种子吗?我想,如果你不想它是随机的,你应该只提供一个种子。这回避了一个明显的问题:为什么你要故意避免使用高级种子而使用系统时间?这让人尖叫对我来说是“XY问题”。长话短说,是一个ctf竞赛。它被建模为一个没有实现os.URADOM的服务器。至少,我认为是这样。
import time
import random

t = int( time.time() * 1000.0 )
random.seed( ((t & 0xff000000) >> 24) +
             ((t & 0x00ff0000) >>  8) +
             ((t & 0x0000ff00) <<  8) +
             ((t & 0x000000ff) << 24)   )