I am trying to modify this GitHub code for my own purposes in the title:
import random
from datetime import datetime, timedelta
min_year=1900
max_year=datetime.now().year
start = datetime(min_year, 1, 1, 00, 00, 00)
years = max_year - min_year+1
end = start + timedelta(days=365 * years)
for i in range(10):
random_date = start + (end - start) * random.random()
print(random_date)
My desired outcome specifically is, for all weekdays (Mon. - Fri.) April 1st, 2023 until July 31st, 2023 print two times (hh:mm:ss) which meet the following conditions:
Are an hour or more apart
Are within the hours of 8 AM - 6 PM (0800 - 1800)
I came up with this before remembering I need to add the two per weekday and hour-apart constraint in somewhere:
import random
from datetime import datetime, timedelta
start = datetime(2023, 4, 1, 00, 00, 00)
end = start + timedelta(days=160)
for i in range(10):
random_date = start + (end - start) * random.random()
no = random_date.weekday()
if no < 5:
print(random_date)
I'll be continuing to work on it, but if anyone has any advice I'd greatly appreciate it! Am fairly new to programming
You can create the time ranges dynamically (guarantees a O(N) runtime where N is the number of days).
Based on your example, the start time must be from [8 AM, 5 PM]; the end time must be [start + 1h, 6 PM].
which should return something like