[Tutor] generating independent random numbers

Joel Levine Joel.Levine at Dartmouth.EDU
Tue Sep 28 02:33:33 CEST 2010


You might try fixing up the following.  I did not match the scale to what you  
are looking for.  But the trick is to take advantage of the time module's association  
of numbers with dates:

import time
import random

""" Sample output

Wed Apr 29 14:35:58 1992
Thu Jun 24 12:04:15 1971
Fri Oct  7 01:29:28 1994
Wed Mar 23 10:33:14 1994
Sun Apr 12 12:17:56 1998
Wed May 12 06:41:33 1971
Mon Jun 15 09:15:31 1998
Fri Sep 14 18:26:22 1979
Fri Apr 28 00:55:57 1972
Fri Mar 26 00:43:12 2010
"""

def re_scale():


     now=float(time.time())
     early=1000000.
     rang=(now-early)
     return time.ctime((random.random())*rang+early)



for i in range(10):
     print re_scale()



More information about the Tutor mailing list