Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random Floating Point
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nathan4102




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
evildaddy911




PostPosted: 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
Nathan4102




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: