Non-sequential shuffle help

Joined
Oct 21, 2008
Messages
1
Reaction score
0
I'm having a bit of difficulty. I'm trying to make a program that takes a command line argument and then shuffles it then prints the shuffled numbers. However, the numbers cannot follow in oder. Ie: 2 cannot follow 3, 6 cannot follow 5, etc.

Here is my code:
Code:
	int numSongs = Integer.parseInt(args[0]);
	

	int[] song = new int[numbSongs];
	for (int position = 0; position < numbSongs; position++) {
	    int list = position;
	    song[position] = list;
	    }
	
   	for (int current = 0; current < numbSongs; current++) {
	    int swap = current + (int) (Math.random() * (numbSongs - current));
	    int tempSong = song[current];
	    song[current] = song[swap];
	    song[swap] = tempSong;
	    if (song[current] == song[swap+1] || song[current] == song[swap-1])
		{ [B][COLOR="Red"]HELP![/COLOR][/B]  }
	    else
		{ System.out.println(song[swap]); }
		
	    
	System.out.println(song[current] + " ");
	}

My problem, I do not know what to put in where it says "HELP" in bold, red letters. I've tried numerous things! Each time, to no avail. Please help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top