title: random distribution of time ranges minimizing overlap
body: <p>I have 5 job arrays of varying length/steps.</p>
  <pre><code>work = [
      np.arange(9),
      np.arange(39),
      np.arange(58),
      np.arange(24),
      np.arange(16)
  ]
  </code></pre>
  <p>And a randomized schedule:</p>
  <pre><code>now = datetime.now().replace(hour=2)
  end = now.replace(hour=22, minute=0, second=0, microsecond=0)
  
  from numpy.random import default_rng
  
  rng = default_rng()
  
  schedule = np.linspace(now.timestamp(), end.timestamp(), sum(len(v) for v in work))
  rng.shuffle(schedule_range)
  worker_schedule = np.split(schedule, np.add.accumulate([len(v) for v in work][:-1]))
  </code></pre>
  <p>I believe this gets me a schedule where the job start times are distributed somewhat randomly with respect to each worker/machine but evenly on aggregate. However each job runtime varies and I would like to avoid hot-spots where I get a bunch of overlapping jobs running simultaneously. Assuming I knew the job run times ahead of time, so:</p>
  <pre><code>work = [
      np.random.uniform(5,10,9),
      np.random.uniform(5,10,39),
      np.random.uniform(5,10,58),
      np.random.uniform(5,10,24),
      np.random.uniform(5,10,16)
  ]
  </code></pre>
  <p>Where each value in the array represents the expected run time for the job step at that index and the array itself is the job. How would I go about creating a schedule that would limit simultaneously running steps to be at maximum N while spreading out the total job steps evenly over fixed period of time T? A nice bonus to have here would be to have random distribution for each step within a job over a fixed time period T but evenly distributed on aggregate over all job steps for that period.</p>
  <p>What concepts can I google to get a good understanding of the problem and known approaches?
  Finally, what would be a good way to visualize this with pyplot? (currently using histograms for the start time distribution but what would be the best way to represent the run-time range)</p>
  <p>Edit 1:
  Job Shop Scheduling problem seems to want to optimize makespan, (time as I understand it) while I would like to keep that fixed but optimize the distribution such that overlap is reduced.</p>