如何使用 Python 生成一個 128 位的隨機字串?
你可以使用 random 模組的 getrandbits 函式生成這些 128 位的隨機字串,該函式將接受一個作為引數的位數。
示例
import random hash = random.getrandbits(128) print(hex(hash))
輸出
這將產生以下輸出 −
0xa3fa6d97f4807e145b37451fc344e58c
廣告
你可以使用 random 模組的 getrandbits 函式生成這些 128 位的隨機字串,該函式將接受一個作為引數的位數。
import random hash = random.getrandbits(128) print(hex(hash))
這將產生以下輸出 −
0xa3fa6d97f4807e145b37451fc344e58c