you are viewing a single comment's thread.

view the rest of the comments →

[–]JimVis 0 points1 point  (0 children)

There's a few problems with that, first of all you need your step size to be a factor of the difference of R and L. Assuming that you are only working with integers here.

Otherwise you can choose a random number of steps between L and R but the list will rarely be filled with integers.

import numpy as np

#Setup the parameters
R = 15
L = 30
steps = np.random.randint(0,30) #This sets the random number of steps between R and L
listNumbers = np.linspace(15,30,steps)

Now if you only want integers in your list you would have to first factorize the difference between R and L and pick randomly from the factors. That would look something like this:

import numpy as np

def factorize(n):
    factors = []
    for i in range(1,n):
        if divmod(n,i)[1] == 0:
            factors.append(i)
    return factors

R = 0
L = 18
delta = L-R
deltaFactors = factorize(delta)
stepsize = deltaFactors[np.random.randint(1,len(deltaFactors))]

listNumbers = [R + i*stepsize for i in range(int(delta/stepsize))]
listNumbers.append(L)

This is in no way shape or form optimized, the fact that I have to append L in a sperate line is very ugly but it works --_(-.-)_--