import java.io.*; import java.util.*; //written by moparisthebest, do whatever the hell you want with it ;) public class RandomizeM3U { public static final String newLine = "\n"; public static void main(String[] args) throws Exception { //check args if(args.length != 2){ System.out.println("Usage: RandomizeM3U INPUT_FILE OUTPUT_FILE"); return; } //read M3U file in FileInputStream fis = new FileInputStream(args[0]); Scanner scan = new Scanner(fis); String firstLine = scan.nextLine()+newLine; //1814 is simply the number of songs I have, can be changed but doesn't need to be ArrayList list = new ArrayList(1814); //reads 2 lines at once because that is how M3U files are formatted while(scan.hasNext()) list.add(scan.nextLine()+newLine+scan.nextLine()+newLine); fis.close(); //randomize list ordering by swapping random indexes String temp; int i1, i2, lSize = list.size(); Random r = new Random(); //higher x goes up to the more random the list becomes, I think the length is sufficient for(int x = 0; x < lSize; ++x){ i1 = r.nextInt(lSize); i2 = r.nextInt(lSize); temp = list.get(i1); list.set(i1, list.get(i2)); list.set(i2, temp); } //write newly randomized list out to file BufferedWriter out = new BufferedWriter(new FileWriter(args[1])); out.write(firstLine); for(String s : list) out.write(s); out.close(); } }