vendredi 23 avril 2021

Algorithm: randomly select points within user-defined ranges, separated by minimum user-defined intervals

I need to develop an algorithm that randomly selects values within user-specified intervals. Furthermore, these values need to be separated by a minimum user-defined distance. In my case the values and intervals are times, but this may not be important for the development of a general algorithm.

For example: A user may define three time intervals (0900-1200, 1200-1500; 1500-1800) upon which 3 values (1 per interval) are to be selected. The user may also say they want the values to be separated by at least 30 minutes. Thus, values cannot be 1159, 1201, 1530 because the first two elements are separated by only 2 minutes.

A few hundred (however many I am able to give) points will be awarded to the most efficient algorithm. The answer can be language agnostic, but answers either in pseudocode or JavaScript are preferred.

Note:

  • The number of intervals, and the length of each interval, are completely determined by the user.
  • The distance between two randomly selected points is also completely determined by the user (but must be less than the length of the next interval)



Aucun commentaire:

Enregistrer un commentaire