Thanks for your quick response! I’ve actually tried a number of different things, most of which worked in PsychoPy but not online unfortunately.
Over 4 practice trials I am presenting participants audio files of 2 pieces written in a major key and 2 pieces written in a minor key in a randomized order. To do this, I sample two pieces from a list of major pieces and two pieces from a list of minor pieces. I then concatenate the lists together and shuffle them.
Once I have shuffled the new list of pieces, I assign each index of the new list to a variable (e.g., pracPiece1). These variables are then used as values in an audio component in builder.
Here is my custom code component to randomly sample the 4 pieces from two lists. I’ve modified it a little by changing the number of files, as well as the names to make it easier to read and less redundant. This code works in PsychoPy but not Pavlovia.
#This code prepares a CSV which randomizes 2 major and 2 minor pieces for the practice trials.
#Make list of major pieces
major = ("testMusic/Major1.wav",
#Make list of minor pieces
minor = ("testMusic/Minor1.wav",
#Randomly sample two pieces from each list
major = np.random.choice(major, 2, replace = False)
minor = np.random.choice(minor, 2, replace = False)
##--Other attempts from random module--##
#major = random.sample(major, 2)
#minor = random.sample(minor, 2)
frames = major + minor
#sample 4 pieces: half major, half minor
## other attempt with random module: pracData = random.sample(frames, 4)
pracData = np.random.shuffle(frames)
#pracData = frames
#assign pieces to variables
pracPiece1 = pracData
pracPiece2 = pracData
pracPiece3 = pracData
pracPiece4 = pracData
I’ve tried changing where in the code component I put this code, and have tried importing numpy.random as well as the random sample function from the random module.
My builder view looks like this, where the randomizer code is in one routine and the presentation of the four pieces in separate routines. I have also tried this format using a loop in the builder view.
The piece routines look like this:
- Some component is missing (when using the random module)
- np (or numpy) is not defined when using the numpy module–I thought this one may work because psychopy uses numpy.
Any help would be appreciated greatly!