Implement an algorithm to shuffle an array of numbers or objects. The algorithm for shuffling should be the following:
for (each index i) {
choose a random index j where j >= i.
swap the elements at indexes i and j.
}
(The constraint about j being greater than or equal to i is actually quite important, if you want your shuffling algorithm to shuffle fairly. Why?)
Sorry the answer is not available at the moment…
If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.
Spread the 'tradition of sharing'.