How to present subset of all images randomly

Hi Michael,

Thank you very much! My apologies, I missed the latter part of your response. Do you know of any ways to randomly sample in JavaScript?

I should have mentioned earlier that I am using the latest version of PsychoPy which translates the Python code to Javascript as such (again with changed filenames to reduce redundancy/improve readability):

major = ["testMusic/Major1.wav", "testMusic/Major2.wav", "testMusic/Major3.wav", "testMusic/Major4.wav"];
minor = ["testMusic/Minor1.wav", "testMusic/Minor2.wav", "testMusic/Minor3.wav", "testMusic/Minor4.wav"];
major = random.choice(major, 2, {"replace": false});
minor = random.choice(minor, 2, {"replace": false});
frames = (major + minor);
pracData = random.shuffle(frames);
pracPiece1 = pracData[0];
pracPiece2 = pracData[1];
pracPiece3 = pracData[2];
pracPiece4 = pracData[3];

I am encountering the following error in Pavolvia:
image
I thought that numpy functions would be recognized by PyschoJS as they are loaded in at the beginning of each PsychoPy script. Again, thank you very much for your input.

Edit: I’ve also tried the following custom Javascript code, borrowing some code for a Fisher-Yates shuffle, but am experiencing some trouble with running the experiment :
(from javascript - Sampling a random subset from an array - Stack Overflow)

#
function getRandomSubarray(arr, size) {
    var shuffled = arr.slice(0), i = arr.length, temp, index;
    while (i--) {
        index = Math.floor((i + 1) * Math.random());
        temp = shuffled[index];
        shuffled[index] = shuffled[i];
        shuffled[i] = temp;
    }
    return shuffled.slice(0, size);
}

var majorArray = ["testMusic/Major1.wav", "testMusic/Major2.wav", "testMusic/Major3", "testMusic/Major4.wav"];

var minorArray = ["testMusic/Minor1.wav", "testMusic/Minor2.wav", "testMusic/Minor3", "testMusic/Minor4.wav"];

var major = getRandomSubarray(majorArray, 2);
var minor = getRandomSubarray(minorArray, 2);

var frames = major.concat(minor);

var pracData = getRandomSubarray(frames, 4);

var pracPiece1 = pracData[0];
var pracPiece2 = pracData[1];
var pracPiece3 = pracData[2];
var pracPiece4 = pracData[3];

This works in the console but running it from PsychoPy throws an error that pracPiece1 is not defined when it attempts to play the first audio file. Is there somewhere else I can redirect this question? Sorry if I am bothering you with too many questions, I am new to the form.