Fix Python – How to get a random number between a float range?

Question

Asked By – Mantis Toboggan

randrange(start, stop) only takes integer arguments. So how would I get a random number between two float values?

Now we will see solution for issue: How to get a random number between a float range?


Answer

Use random.uniform(a, b):

>>> import random
>>> random.uniform(1.5, 1.9)
1.8733202628557872

This question is answered By – Yuri Stuken

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0