A
A
Andrey Chereshnev2020-07-09 16:55:01
JavaScript
Andrey Chereshnev, 2020-07-09 16:55:01

How to make a script to launch random mp3 files?

There are a lot of mp3 files.
It is necessary that the js file calculates the order of playing files randomly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2020-07-09
@Stalker_RED

function shuffleArray(array) {
    for (let i = array.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [array[i], array[j]] = [array[j], array[i]];
    }
}

es6 implementation of Durstenfelds shuffle
algorithm brought from here: https://stackoverflow.com/a/12646864

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question