
-----------------------------------
Nathan4102
Thu Apr 04, 2013 2:26 pm

Random Floating Point
-----------------------------------
I'm using this code right now to get a random number between 0.03 seconds and 0.1 seconds:

[CODE]time.sleep(0.05 + random.randrange(0.03, 0.1))[/CODE]

but apparently randrange can only be used with integers... Is there a randrange or randint equivielnt that I could use with floating points? I could just do this:

[CODE]time.sleep(0.05 + (random.randrange(3, 10) / 100))[/CODE]

But if there was a random number generator that worked with floating points, that would be better. :)

Thanks, 
Nathan

-----------------------------------
evildaddy911
Thu Apr 04, 2013 2:39 pm

RE:Random Floating Point
-----------------------------------
there is almost always a random function giving a floating-point between 0 and 1. I suggest trying something like random.rand()
NOTE: i have never coded in python; this is just speculation based on experience with other languages

-----------------------------------
Nathan4102
Thu Apr 04, 2013 2:40 pm

RE:Random Floating Point
-----------------------------------
Just got it, round(random.uniform(0.03, 0.1), 2)
Thanks for trying ;)
