Python 3 - Number uniform() Method


The uniform() method returns a random float r, such that x is less than or equal to r and r is less than y.


Following is the syntax for the uniform() method −

uniform(x, y)

Note − This function is not accessible directly, so we need to import uniform module and then we need to call this function using random static object.


  • x − Sets the lower limit of the random float.

  • y − Sets the upper limit of the random float.

Return Value

This method returns a floating point number r such that x <= r < y.


The following example shows the usage of uniform() method.

import random

print ("Random Float uniform(5, 10) : ",  random.uniform(5, 10))
print ("Random Float uniform(7, 14) : ",  random.uniform(7, 14))


Let us run the above program. This will produce the following result −

Random Float uniform(5, 10) :  5.52615217015
Random Float uniform(7, 14) :  12.5326369199