Python Random random() Method
The random.random() function generates random floating numbers in the range of 0.1, and 1.0. It takes no parameters and returns values uniformly distributed between 0 and 1. There are various functions associated with the random module are:
- Python random()
- Python randrange()
- Python randint()
- Python seed()
- Python choice(), and many more. We are only demonstrating the use of the random() function in this article.
Python Random – random() Function
There are certain situations that involve games or simulations which work on a non-deterministic approach. In these types of situations, random numbers are extensively used in the following applications:
- Creating pseudo-random numbers on Lottery scratch cards
- reCAPTCHA on login forms uses a random number generator to define different numbers and images
- Picking a number, flipping a coin, and throwing of a dice related games required random numbers
- Shuffling deck of playing cards
In Python, random numbers are not generated implicitly; therefore, it provides a random module in order to generate random numbers explicitly. A random module in Python is used to create random numbers. To generate a random number, we need to import a random module in our program using the command:
import random
Contact Us