Hi Matheo!
Just making sure I understand the problem.
whats the formula to achive this?
You already described the formula, so I'm guessing that you're asking how can you automatically produce a list because you don't actually have four artists and 12 songs total, but many artists and hundreds of songs total, and producing a randomized list by hand is just too tedious.
Is your music on your computer or somewhere else? If it's on your computer then my guess is that there are many programs out there that include a randomized playlist feature. Some programs are probably better than others, so some may make sure that the same artist doesn't have consecutive songs, and some may not.
--Percy