Non-sequential shuffle help

Discussion in 'Java' started by Smartfood, Oct 21, 2008.

  1. Smartfood

    Smartfood

    Joined:
    Oct 21, 2008
    Messages:
    1
    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!
    Smartfood, Oct 21, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pieter_hordijk@hotmail.com

    Shuffle an array of integers.

    pieter_hordijk@hotmail.com, Apr 21, 2005, in forum: Java
    Replies:
    12
    Views:
    14,477
    Lee Ryman
    Apr 26, 2005
  2. Maciej Gawinecki

    non-sequential XSL(T) processing

    Maciej Gawinecki, Oct 5, 2005, in forum: XML
    Replies:
    2
    Views:
    415
  3. j0ecanad1an80

    Shuffle method error

    j0ecanad1an80, Jun 19, 2006, in forum: Java
    Replies:
    4
    Views:
    672
    blmblm@myrealbox.com
    Jun 19, 2006
  4. s88

    non sequential execution...

    s88, Nov 3, 2005, in forum: C Programming
    Replies:
    7
    Views:
    376
    Kenny McCormack
    Feb 13, 2006
  5. Jeff Moore

    Array.shuffle/Array.shuffle!

    Jeff Moore, Aug 24, 2008, in forum: Ruby
    Replies:
    6
    Views:
    145
    Alexei Broner
    Oct 9, 2008
Loading...

Share This Page