如何使用 Python 生成一個 128 位的隨機字串?


你可以使用 random 模組的 getrandbits 函式生成這些 128 位的隨機字串,該函式將接受一個作為引數的位數。

示例

import random
hash = random.getrandbits(128)
print(hex(hash))

輸出

這將產生以下輸出 −

0xa3fa6d97f4807e145b37451fc344e58c

更新於: 2020-03-05

2k+ 瀏覽

開啟你的 職業生涯

完成此課程獲得認證

開始學習
廣告
© . All rights reserved.