Thread: Shuffle rows in an array

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    7

    Shuffle rows in an array

    Is it possible to shuffle just the rows in an array?

    Say you have:

    1, 2, 3, 4
    2, 3, 4, 5
    3, 4, 5, 6

    to turn into:

    2, 3, 4, 5
    1, 2, 3, 4
    3, 4, 5, 6

    or any other random order. Thank you

  2. #2
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    No, it is not possible. Unfortunately, even with our technology that can calculate Pi to over trillion digits in less than four days, we haven't yet mastered the art of shuffling items in an array.

    Kidding aside, of course it is possible. There are probably several dozen different ways to do it, too, and all of them depend on what kind of data structures you're using.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    132
    It is possible to do that. You could use a repetition statement to choose the current row to shuffle, and you could use a helper two-dimensional array to put the shuffled elements; then, you could either print the new array or copy its contents to the old array, and print it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Array Shuffle
    By omGeeK in forum C Programming
    Replies: 3
    Last Post: 02-14-2011, 07:48 PM
  2. adding up the rows of a 2D array
    By youngvito in forum C Programming
    Replies: 31
    Last Post: 06-11-2009, 01:06 PM
  3. shuffle 2-dimensional array
    By patkhor in forum C Programming
    Replies: 5
    Last Post: 11-26-2008, 03:51 PM
  4. Array Shuffle
    By ypramesh in forum C Programming
    Replies: 2
    Last Post: 04-08-2006, 11:01 AM
  5. sum rows & columns in array
    By ronenk in forum C Programming
    Replies: 7
    Last Post: 06-20-2004, 04:16 AM