Friday, December 27, 2024
Google search engine
HomeLanguagesPython | os.urandom() method

Python | os.urandom() method

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.urandom() method is used to generate a string of size random bytes suitable for cryptographic use or we can say this method generates a string containing random characters.

Syntax: os.urandom(size)

Parameter:
size: It is the size of string random bytes

Return Value: This method returns a string which represents random bytes suitable for cryptographic use.

Example #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) 


Output:

b'\xe2\xaf\xbc:\xdd'
Last Updated :
18 Oct, 2019
Like Article
Save Article
Similar Reads
Related Tutorials
RELATED ARTICLES

Most Popular

Recent Comments