gpt4 book ai didi

Python 3 操作系统.urandom

转载 作者:太空狗 更新时间:2023-10-29 20:36:04 32 4
gpt4 key购买 nike

在哪里可以找到有关 os.urandom 的完整教程或文档?我需要获取一个随机 int 以从 80 个字符的字符串中选择一个 char。

最佳答案

如果你只需要一个随机整数,你可以使用random.randint(a, b) from the random module .

如果您出于加密目的需要它,请使用 random.SystemRandom().randint(a, b),它利用了 os.urandom()

Example

import random

r = random.SystemRandom()
s = "some string"
print(r.choice(s)) # print random character from the string
print(s[r.randrange(len(s))]) # same

关于Python 3 操作系统.urandom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13217016/

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