Pure Programmer
Blue Matrix


Cluster Map

Project: Shuffle Deck

Write a function that takes a list of integers and then shuffles them in place into a random order. You can test the function by passing in a list of the integers 0-51. Then print the shuffled array as playing cards A, 2-10, J, Q, K and suits Clubs, Spades, Diamonds and Hearts by writing a function that converts an integer 0-51 into a card value and suit. Use appropriate assertions.

The shuffling algorithm to use is to randomly select on element of the array. Swap it with the first element of the list. Then randomly select an element from the elements after the first. Swap that random element with the second in the list. Continue until all the elmement have been swapped.

Output
$ perl ShuffleDeck.pl "rand" is not exported by the Math::Trig module Can't continue after import errors at ShuffleDeck.pl line 11. BEGIN failed--compilation aborted at ShuffleDeck.pl line 11.

Solution