I made a random music player for Slick2D, feel free to use it for whatever you want :)

package *your package here*;

import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;

public class RandomMusicPlayer {

public void RandomMusic() throws SlickException{

Music music1 = new Music("res/music1.wav");

int random;

random = (int)(Math.random() * 10); //change the 10 for more or less tracks

if(random == 1){
System.out.println("Track n.1");

Then, in the state you want to have random music:

package *your package here*;

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class *your class here* extends BasicGameState{

int time = 0;
int duration = 2000;

RandomMusicPlayer musicObj = new RandomMusicPlayer();

public Play(int state){

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
time = 0;

public int getID(){
return 1;


This will play a different song every 2 seconds, but if you want it to play every 2 minutes (or more or less) just change the duration integer just keep in mind that it is in millisecond, enjoy ;-)