Computer Science Canada

Random Floating Point

Author:  Nathan4102 [ Thu Apr 04, 2013 2:26 pm ]
Post subject:  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))


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))


But if there was a random number generator that worked with floating points, that would be better. Smile

Thanks,
Nathan

Author:  evildaddy911 [ Thu Apr 04, 2013 2:39 pm ]
Post subject:  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

Author:  Nathan4102 [ Thu Apr 04, 2013 2:40 pm ]
Post subject:  RE:Random Floating Point

Just got it, round(random.uniform(0.03, 0.1), 2)
Thanks for trying Wink


: