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
15
KoiKoi.hs
15
KoiKoi.hs
|
@ -62,13 +62,8 @@ shuffle l =
|
||||||
aux (length l) l
|
aux (length l) l
|
||||||
where
|
where
|
||||||
aux n [] = return []
|
aux n [] = return []
|
||||||
aux n [a] = return [a]
|
aux n (h:t) = do
|
||||||
aux n l = do
|
cut <- randomRIO (0, n-1)
|
||||||
cut <- randomRIO (0, n - 1)
|
shuffled <- shuffle t
|
||||||
let (top, bottom) = splitAt cut l
|
let (top, bottom) = splitAt cut shuffled
|
||||||
shuffledTop <- aux cut top
|
return $ top ++ h : bottom
|
||||||
shuffledBottom <- aux (n - cut) bottom
|
|
||||||
reorder <- randomRIO (False, True)
|
|
||||||
return $ if reorder
|
|
||||||
then shuffledTop ++ shuffledBottom
|
|
||||||
else shuffledBottom ++ shuffledTop
|
|
||||||
|
|
Loading…
Reference in a new issue