Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created August 28, 2021 17:35
Show Gist options
  • Select an option

  • Save marcosan93/e35f2755fdd0ea3bc85744f4c08d7280 to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/e35f2755fdd0ea3bc85744f4c08d7280 to your computer and use it in GitHub Desktop.
def random_dob(start, end, n):
"""
Generating a list of a set number of timestamps
"""
# The timestamp format
frmt = "%Y-%m-%d"
# Formatting the two time periods
stime = datetime.datetime.strptime(start, frmt)
etime = datetime.datetime.strptime(end, frmt)
# Creating the pool for random times
td = etime - stime
# Generating a list with the random times
times = [(random.random() * td + stime).strftime(frmt) for _ in range(n)]
return times
df['dob'] = random_dob("1980-01-01", "2006-01-01", num_users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment