How to get a random number between a float range?

Mantis Toboggan picture Mantis Toboggan · May 22, 2011 · Viewed 407.7k times · Source

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

Answer

Yuri Stuken picture Yuri Stuken · May 22, 2011

Use random.uniform(a, b):

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