2022-07-26 10:07:31 +00:00
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
from numpy.random import Generator, MT19937
|
|
|
|
|
|
|
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
|
class MT19937Random:
|
|
|
|
|
"""基于 numpy 实现的动态删除时间设计
|
2022-07-26 10:07:31 +00:00
|
|
|
|
——MXtao_dada | 小男孩赛高!
|
|
|
|
|
笑死,不然你猜猜为啥 requirements.txt 有 numpy ?
|
|
|
|
|
——洛水居室
|
|
|
|
|
笑死,虽然说我是写的 )
|
|
|
|
|
不得不说让我想到一个事情,万一以用户的ID做随机数种子呢,这样就可以决定某个账户一开始就是非洲或者欧洲 )
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
2022-09-08 01:08:37 +00:00
|
|
|
|
"""创建随机数生成器"""
|
2022-07-26 10:07:31 +00:00
|
|
|
|
self.send_time = time.time()
|
|
|
|
|
self.generator = Generator(MT19937(int(self.send_time)))
|
|
|
|
|
|
|
|
|
|
def random(self, low: int, high: int) -> int:
|
|
|
|
|
if self.send_time + 24 * 60 * 60 >= time.time(): # 86400秒后刷新随机数种子
|
|
|
|
|
self.send_time = time.time()
|
|
|
|
|
self.generator = Generator(MT19937(int(self.send_time)))
|
|
|
|
|
return int(self.generator.uniform(low, high))
|