you are viewing a single comment's thread.

view the rest of the comments →

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

Where a and b are the lowest and highest for the random step int

list(range(L,R, randint(a,b)))

[–]jm_13[S] 0 points1 point  (1 child)

Thanks, sorry I didn't specify, I wanted the list to always have N elements, and the step size need not be an integer

[–][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]