dmas wrote:
Hey, at the beginning after the bell. The lady tells me to wait and there is an error from the attachment.
I might figured out a solution to this:
-Open the file scripts/toy/play.groovy with your favorite editor.
-Find the two lines (roughly line 100):
Code:
final probabilities = sessions.withIndex().collect { s, idx -> [idx] * s.probability }.sum();
final session = sessions[probabilities[getRandom(probabilities.size)]];
and replace them with this:
Code:
final probabilities = sessions.collect { s -> s.probability }; // Collect probabilities
final totalProbability = probabilities.sum(); // Calculate total probability
def cumulativeProbability = 0;
final cumulativeProbabilities = probabilities.collect { // Calculate cumulative probabilities
cumulativeProbability += it;
cumulativeProbability;
};
final randomValue = Math.random() * totalProbability; // Generate random value
final selectedSessionIndex = cumulativeProbabilities.findIndexValues { it >= randomValue }.first(); // Find index of selected session
final session = sessions[selectedSessionIndex]; // Retrieve selected session
(Yes the credits go to chatgpt)
I can't promise anything but it should work now.