How to make the target’s position different from the previous target’s position?

The way I approach this kind of issue, to avoid random locations being too close to previous random locations, is to create a grid of jittered points and then shuffle them.

I’ve just updated my points on a grid demo to include optional jitter. You could create a random list of points with something like

rows = 8
columns = 10
gap = [.1,.1]
jitter = .05
points = []
for Jdx in range (rows):
    for Idx in range(columns):
            points.append([(1+Idx-(columns+1)/2)*gap[0]+random()*jitter-random()*jitter,((rows+1)/2-Jdx-1)*gap[1]+random()*jitter-random()*jitter]) 
shuffle(points)

Then use points[trials.thisN%len(points)] for the location of an object in a loop called trials. %len(points) means that it will go back to the start once all points have been used.

1 Like