Hello all,
How to make the position variable different from the previous trail? That is, when the participant does the experiment, the position of trail N and trail N-1 are different. I don’t want to use the method of generating excel tables, I want to realize this randomization in psychopy, where should I add this code?I appreciate your help.
Hello,
Here is a possible solution using the random
library. This solution will only work for offline experiments but should also be easy to implement for online experiments.
# Start Experiment
import random
def randomLocation():
return round(random.uniform(-1, 1), 3)
# Start Routine
currentLocation = [randomLocation(), randomLocation()]
Then, set the position to change on every repeat and set it to $currentLocation
.
You might need to reduce the range from -1 → 1, to -0.8 → 0.8, depending on your stimulus size.
Chen
Thank you very much!!
But with a little tweaking in the coder,
Put currentLocation = [randomLocation(), randomLocation()] before polygon.setPos()
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.