Random-Function-Unveiling-the-Power-of-Randomness-in-Programming.ppt
Random-Function-Unveiling-the-Power-of-Randomness-in-Programming.ppt
Produces random numbers or values. Offers different functions for specific use cases.
The Random Module in
Python
To use random functions in Python, import the random
module:
import random
Overview of Random Functions
Function Description Example
Cryptography Testing
Random key generation Generating random test
for secure data for software
communication. validation.
Example Program
import random
print(random.randint(1, 6)) # Simulates a dice
roll
print(random.choice(['head', 'tail'])) #
Simulates a coin toss
Q 1: What will random.randint(1, 5) return
(A) (B)
Any integer between 0 and 5. Any integer between 1 and 4.
(C) (D)
Any integer between 1 and 5. Any integer between 0 and 4.
(C) (D)
uniform(a, b) shuffle()
(C) (D)
Rearrange the list in random order. Remove duplicates from the list
(C) (D)
A random float between 1 and 10. A random integer between 1 and 10.