import datetime, time import random def year_start(year): return time.mktime(datetime.date(year, 1, 1).timetuple()) def rand_day(year): stamp = random.randrange(year_start(year), year_start(year + 1)) return datetime.date.fromtimestamp(stamp)
Edit: The starting dates used in Michael Dunns answer are better to use timestamps then! You might want to combine the use of ordinals with this.
plundra
source share