Python中的OS模塊提供了與操作係統進行交互的函數。操作係統屬於Python的標準實用程序模塊。該模塊提供了使用依賴於操作係統的函數的便攜式方法。
os.urandom()
方法用於生成適合加密使用的大小隨機字節的字符串,或者可以說此方法生成包含隨機字符的字符串。
用法: os.urandom(size)
參數:
size:它是字符串隨機字節的大小
返回值:此方法返回一個字符串,該字符串表示適合加密用途的隨機字節。
範例1:
# Python program to explain os.urandom() method
# importing os module
import os
# Declaring size
size = 5
# Using os.urandom() method
result = os.urandom(size)
# Print the random bytes string
# Output will be different everytime
print(result)
輸出:
b'\xe2\xaf\xbc:\xdd'
相關用法
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python Decimal max()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python os.rmdir()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python Decimal min()用法及代碼示例
- Python os.readlink()用法及代碼示例
- Python os.writev()用法及代碼示例
- Python os.readv()用法及代碼示例
- Python PIL RankFilter()用法及代碼示例
- Python os.rename()用法及代碼示例
- Python os.sendfile()用法及代碼示例
注:本文由純淨天空篩選整理自Rajnis09大神的英文原創作品 Python | os.urandom() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。