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 bytesReturn 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) |
b'\xe2\xaf\xbc:\xdd'
Recommended Posts:
- class method vs static method in Python
- Python | set() method
- Python | os.dup() method
- Python | next() method
- Python | os.pread() method
- Python | os.fsencode() method
- Python | os.isatty() method
- Python | os.device_encoding() method
- Python | setattr() method
- Python | os.system() method
- Python | os.sched_rr_get_interval() method
- Python | Decimal ln() method
- Python | os._exit() method
- Python | os.WEXITSTATUS() method
- Python | os.abort() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




