uniform() is a method specified in random library in Python 2 and Python 3.
Nowdays, in general day-day tasks there’s always the need to generate random numbers in a range. Normal programming constructs require a method more than just one word to achieve this particular task. In python, there’s an inbuilt method, “uniform()” which performs this task with ease and using just the one word. This method is defined in “random” module
Syntax : uniform(int x, int y)
x Specifies the lower limit of the random number required to generate.
y Specifies the upper limit of the random number required to generate.
Returns : Returns the generated floating point random number between lower limit and upper limit
Code #1 : Code to generate float random number.
The random number generated between 4 and 9 is : 7.494931618830411
There are many possible applications that can be thought of this function, some of the notable being generating random numbers in casino games, for lottery or custom games.
Below is the game that decided the winner on the basis on closeness to a certain value.
Code #2 : Application of uniform() – A Game
The winner of game is : Player2
- Python - Uniform Distribution in Statistics
- Python - Uniform Discrete Distribution in Statistics
- Python Number | fabs() method
- Python Number | cmp(list) method
- Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function
- class method vs static method in Python
- 21 Number game in Python
- Python | Superfactorial of a number.
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | Get the number of keys with given value N in dictionary
- Python | Number to Words using num2words
- Python | Insert a number in string
- Python | First occurrence of True number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.