gpt4 book ai didi

python - Python 中的随机模块是否有替代方案?

转载 作者:行者123 更新时间:2023-11-28 20:09:21 26 4
gpt4 key购买 nike

我正在使用 Trypython.org , 发现并没有包含随机模块,于是好奇起来。

是否有替代方法可以在不导入 random 的情况下生成特定范围内的随机数?

最佳答案

它非常丑陋、不可靠,而且速度不是很快,但它确实有效:

>>> import time
>>> t = time.time()
>>> int(str(t-int(t))[2:])%100 #Keeping only the numbers after the decimal point, otherwise you would get the same "random" number each second
33

此处的范围是 [0,99](比较模 100)。使用它需要您自担风险。

关于python - Python 中的随机模块是否有替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10930386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com