Within a specific integer range [a, b] I would like to generate n lists, each consisting of z non-overlapping, random intervals with a minimum interval width of w. The non-overlap condition is to be understood within a single such list.
Example for a=0, b=100, n=4, z=3, w=5:
1. [ [1, 17], [57, 83], [89, 98] ]
2. [ [5, 23], [42, 49], [60, 78] ]
3. [ [70, 76], [80, 89], [93, 99] ]
4. [ [20, 62], [67, 81], [82, 93] ]
At the moment I use numpy.linspace to return evenly spaced values over the [a,b] interval for the left interval boundaries, then introduce a small random variation for each of these values. Within two such boundaries I then try to place the right interval boundaries while respecting the minimal width requirement. However, my approach is very computationally expensive.
What is the most efficient way of achieving my goal in Python?
Aucun commentaire:
Enregistrer un commentaire