Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created August 27, 2021 15:49
Show Gist options
  • Select an option

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

Select an option

Save marcosan93/9b32ee02e9cce35c7e0d92e586eaef7a to your computer and use it in GitHub Desktop.
def randomtimes(start, end, n):
"""
Generates random time stamps based on a given amount between two time periods.
"""
# The timestamp format
frmt = "%Y-%m-%d %H:%M:%S"
# 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
# Setting the start and end times
start = "2021-08-01 00:00:00"
end = "2021-08-24 00:00:00"
df['last_login'] = randomtimes(start, end, num_users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment