Relic song

So i was playing through a randomizer now i don’t know if you can encounter meloetta but if you where to encounter meloetta would you get relic song afther defeating or capturing her in a randomizer or do you have to do all her puzzles?

Relic Song can only be unlocked from the encounter in the cave after obtaining all Mysterious Scrolls.