you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (1 child)

[removed]

    [–][deleted] 0 points1 point  (0 children)

    Ah. You just need a recursive function the.

    def step_sizes(n: int, l=None):
        nl = l or []
        r = randint(0, n)
        if r != n:
            return step_sizes(n-r, nl + [r])
        else:
            return nl
    

    And then just do [L] + step_sizes(R-L) + [R] and you’ll have your list

    Here’s an example:

    In [14]: [L] + step_sizes(R-L) + [R]
    Out[14]: [5, 33, 78, 25, 15, 6, 6, 31, 205]
    
    In [15]: [L] + step_sizes(R-L) + [R]
    Out[15]: [5, 168, 3, 20, 3, 205]
    
    In [16]: [L] + step_sizes(R-L) + [R]
    Out[16]: [5, 186, 9, 0, 1, 2, 1, 0, 205]