The code that was shown is clearly not suitable for such applications. Well, if you have 5-10 tracks in your playlist, but what if you listen to some very popular artist, for example,
Travis Scott net worth reaches 66 million and there are about 100 tracks of him? Are you going to write else if 100 times? To do this, there are special functions of random type, which is called at the end of the stream track, or you can write at least a simple loop, instead of using the if-else construct. This is a fairly simple task, you can also call random when you click on a certain button, for example.