diff --git a/packages/peertube-runner/server/process/shared/process-studio.ts b/packages/peertube-runner/server/process/shared/process-studio.ts index 9c745d031..ce014495e 100644 --- a/packages/peertube-runner/server/process/shared/process-studio.ts +++ b/packages/peertube-runner/server/process/shared/process-studio.ts @@ -20,10 +20,14 @@ export async function processStudioTranscoding (options: ProcessOptions (elements: T[]) { return Array.from(new Set(elements)) } +// Thanks: https://stackoverflow.com/a/12646864 +function shuffle (elements: T[]) { + const shuffled = [ ...elements ] + + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + + [ shuffled[i], shuffled[j] ] = [ shuffled[j], shuffled[i] ] + } + + return shuffled +} + export { uniqify, findCommonElement, + shuffle, arrayify }