Shuffling a 2D Array

For this challenge we will investigate how to create a 2D array to store the value from 1 to 100 in a 10×10 array. We will then write an algorithm to shuffle the content of this array.
2d-array-1-100
See the code below to see how the array can be initialised to contain all numbers from 1 to 100 and how it is then displayed on screen.

Your Challenge


The aim of this challenge will is add a function to the code above to shuffle all 100 values inside the array:
shuffling-2d-array

Solution


Check the following flowchart for a solution that:

  • Accesses each value of the array one by one (using two nested loops),
  • Swaps each value: it swaps the value with another value of the array at a random position.

flowchart-shuffling-2d-array

Did you like this challenge?

Click on a star to rate it!

Average rating 4.1 / 5. Vote count: 78

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,