Shorten shuffle and improve its randomness (previous one declusters poorly)
This commit is contained in:
parent
77bc2faa4e
commit
51436f4eb2
1 changed files with 5 additions and 10 deletions
13
KoiKoi.hs
13
KoiKoi.hs
|
@ -62,13 +62,8 @@ shuffle l =
|
|||
aux (length l) l
|
||||
where
|
||||
aux n [] = return []
|
||||
aux n [a] = return [a]
|
||||
aux n l = do
|
||||
aux n (h:t) = do
|
||||
cut <- randomRIO (0, n-1)
|
||||
let (top, bottom) = splitAt cut l
|
||||
shuffledTop <- aux cut top
|
||||
shuffledBottom <- aux (n - cut) bottom
|
||||
reorder <- randomRIO (False, True)
|
||||
return $ if reorder
|
||||
then shuffledTop ++ shuffledBottom
|
||||
else shuffledBottom ++ shuffledTop
|
||||
shuffled <- shuffle t
|
||||
let (top, bottom) = splitAt cut shuffled
|
||||
return $ top ++ h : bottom
|
||||
|
|
Loading…
Reference in a new issue