randomSelect(probabilities) {
        // Return index of chosen item
        let sumProbabilities = 0;
        for (let i = 0; i < probabilities.length; ++i) {
            sumProbabilities += probabilities[i];
        }

        let r = Math.random() * sumProbabilities;
        for (let i = 0; i < probabilities.length; ++i) {
            r -= probabilities[i];
            if (r <= 0) {
                return i;
            }
        }
        return 0; // return first (most probable) as a fallback
    }
Selects an item randomly based on the specified probabilities.
@param {import("../transformers.js").DataArray} probabilities An array of probabilities to use for selection.
@returns {number} The index of the selected item.