1
Fork 0
This repository has been archived on 2023-12-08. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2022FuncProg-project2-patience/lib/Shuffle.hs

24 lines
563 B
Haskell

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