Open In App

Python | os.urandom() method

Last Updated : 18 Oct, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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 : Python3
# 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'

Next Article
Article Tags :
Practice Tags :

Similar Reads