How to import random in python?
![](https://pythonpoint.net/wp-content/uploads/2020/12/Yellow-and-Pink-Beauty-and-Fashion-Blog-Banner-6-1024x576.jpg)
Random module- Function in this module depends upon the pseudo random number generator function random.
random()- Generates a random float number 0.0 to 1.0.
syntax:-
import random random.random()
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-1145-1024x133.png)
randint()- Returns a random integer between the specified integers.
syntax:-
import random random.randint(1,100)
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-1144-1024x146.png)
randrange()- Returns a randomly selected element from the range.
e.g.,
import random random.randrange(1, 10, 2)
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-1143-1024x154.png)
choice()- Returns a randomly selected element from non-empty sequence.
e.g.,
import random random.choice("pythonpoint")
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-1146-1024x149.png)
This is how we import random in python.
Subscribe
Login
Please login to comment
0 Discussion