diff --git a/CCard.hs b/CCard.hs index 7b8e2be..c56ffc7 100644 --- a/CCard.hs +++ b/CCard.hs @@ -2,6 +2,7 @@ module CCard where import Data.Word (Word64) import Data.Bits (setBit, (.|.), (.&.), shift, xor, testBit) +import System.Random (randomRIO) data Flower = Pine @@ -72,3 +73,14 @@ pair card1 card2 = flower card1 == flower card2 cards :: [Card] cards = [Pine0 .. Phoenix] + +shuffle :: [a] -> IO [a] +shuffle l = + aux (length l) l + where + aux n [] = return [] + aux n (h:t) = do + cut <- randomRIO (0, n-1) + shuffled <- shuffle t + let (top, bottom) = splitAt cut shuffled + return $ top ++ h : bottom