1
Fork 0

Added a deck of cards functionality

This commit is contained in:
Tibo De Peuter 2022-11-07 08:04:11 +01:00
parent 58f9a03123
commit 7a4ef79bf9
5 changed files with 76 additions and 15 deletions

24
lib/Shuffle.hs Normal file
View file

@ -0,0 +1,24 @@
module Shuffle (
shuffle
) where
import Data.List
import System.Random
seed = 20
-- Shuffle a list of values.
shuffle :: [a] -> [a]
shuffle l = map (l !!) $ generateIndices $ length l
-- Generate indices to map the elements of a list over so that they
-- are randomly shuffled.
generateIndices :: Int -> [Int]
generateIndices size = take size uniqueList
where randomList = randomRs (0, size - 1) randomGen
uniqueList = nub randomList
-- Generate a random generator
-- TODO Écht random maken?
randomGen :: StdGen
randomGen = mkStdGen seed