Rozwinięcie komentarza stąd:
function rotate() {
const rotate = document.querySelector(".cube");
const translate = ["animation", "animation-1", "animation-2", "animation-3"]; // tablica z samymi nazwami klas
const randomClassName = translate[Math.floor(Math.random() * translate.length)]; // losowanie od 0 do długości tablicy
console.log('randomClassName:', randomClassName);
rotate.classList.add(randomClassName); // dodanie wylosowanej klasy jeden raz
}