Python - Generate Random Dates To Create Gantt Sequenced Tasks
The idea is to generate random but sequenced dates based on workload estimation in python. The goal is to have an output like this: Task, Start_date, End_date task1, 01/06/2020,
Solution 1:
You need a seed:
random.seed(a=None)
a is the seed value. If it is None then the system time is used by default. Add this line before you start generating random dates. Don't set the seed inside a loop because that causes bugs.
You can do something like this:
import datetime
import random
# startdate
start_date = datetime.date(2020, 1, 1)
# enddate
end_date = datetime.date(2020, 2, 1)
time_between_dates = end_date - start_date
days_between_dates = time_between_dates.days
#workload in days
random.seed(a=None)
tasks = 10
for i in range(tasks):
random_number_of_days = random.randrange(days_between_dates)
random_date = start_date + datetime.timedelta(days=random_number_of_days)
print("Task" + str(i+1) + "," + str(start_date) + "," + str(random_date))
start_date = random_date # by @Makram
You will need to change what start date is, too, unless you want all of them to start at the same date.
You can make a list of startdates and then index them with i. This will allow you to have a specific start date for each of the tasks.
Post a Comment for "Python - Generate Random Dates To Create Gantt Sequenced Tasks"