日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python getostime_Python os.getrandom()用法及代码示例

發布時間:2023/12/2 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python getostime_Python os.getrandom()用法及代码示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python中的OS模塊提供了與操作系統進行交互的功能。操作系統屬于Python的標準實用程序模塊。該模塊提供了使用依賴于操作系統的功能的便攜式方法。

os.getrandom()方法用于生成適合加密使用的大小隨機字節的字符串,或者可以說此方法生成包含隨機字符的字符串。它也可以用來為user-space隨機數生成器提供種子。它可以返回的字節數少于請求的字節數。

用法: os.getrandom(size, flag)

參數:

size:它是字符串隨機字節的大小

flag:它是一個位掩碼,可以包含零個或多個標志或。標志為os.GRND_RANDOM和GRND_NONBLOCK。

返回值:此方法返回一個字符串,該字符串表示適合加密用途的隨機字節。

標志–

os.GRND_NONBLOCK: If this flag is set then getrandom() does not block but instead immediately raises BlockingIOError if no random bytes are available to read.

os.GRND_RANDOM: If this bit is set then random bytes are drawn from the /dev/random pool.

示例1:

# Python program to explain os.getrandom() method

# importing os module

import os

# Declaring size

size = 5

# Using os.getrandom() method

# Using os.GRND_NONBLOCK flag

result = os.getrandom(size, os.GRND_NONBLOCK)

# Print the random bytes string

# Output will be different everytime

print(result)

輸出:

b'5\n\xe0\x98\x15'

示例2:

# Python program to explain os.getrandom() method

# importing os module

import os

# Declaring size

size = 5

# Using os.getrandom() method

# Using os.GRND_RANDOM flag

result = os.getrandom(size, os.GRND_RANDOM)

# Print the random bytes string

# Output will be different everytime

print(result)

輸出:

b'\xce\xc8\xf3\x95%'

總結

以上是生活随笔為你收集整理的python getostime_Python os.getrandom()用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。