Randomly select an interval according to the elements in the list as the step size

list1=]
how to use python to generate random intervals such as
:
[1jue 2]
[5jue 25]
[19jue 74]
[36jue 44]
[100124]
within a given range of [1200].

Feb.28,2021

na

import random

list1 = [1,20,55,8,24]

bound = (1, 200)

for step in list1:
    lower = random.randint(bound[0], bound[1] - step)
    print([lower, lower + step])

will not python


import random

list1 = [1,20,55,8,24]
random.sample([i for i in list1 if i >= 1 and i <= 200], 2)

take a closer look, it is true that my answer is not the answer to the question.

wait for the correct answer.

Menu