Problem solving with programming: Program to shuffle an array
In some applications like card games, we need to shuffle an array of objects. In this post we will consider the problem of shuffling an array of numbers so that the same algorithm would be applicable for any type of arrays.We use the random number generator in this algorithm. Let us consider an array of n numbers. It's element are in the range of 0 to n-1 indices. We first select a random number between 0 to n-1 indices,and swap the random element with the last element. In the next iteration, we exclude the last element (thus reducing the array size by 1) and repeat the same procedure.
Read full article from Problem solving with programming: Program to shuffle an array
No comments:
Post a Comment