jeudi 19 septembre 2019

Python: Random list of numbers in a range keeping with minimum distance and maximum distance

samples = [
    [9*i + s for i, s in enumerate(sample)]
     for sample in itertools.combinations(range(15), 4)
    ]

What should I change in this code to generate 4 random numbers between 0 and 60 where the minimum distance between any two numbers in the list will be at least 10 or more and maximum distance between two adjacent numbers will be at most 20 or less. Something like [10, 28, 45, 57] or [3, 21, 32, 52]. Thank you.




Aucun commentaire:

Enregistrer un commentaire