summaryrefslogtreecommitdiff
path: root/Shuffle.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2016-01-28 13:27:16 -0700
committerJoe Zhao <ztuowen@gmail.com>2016-01-28 13:27:16 -0700
commit9d9cfd3c2f7ab36982cb569027cf831e95ee42ea (patch)
tree2a63b4d23ae6073d051c5a9802ab000439f89f78 /Shuffle.hs
parent7c8e53da6280751598e1c62fdaca314d5a4b0aed (diff)
downloadhaskbox-9d9cfd3c2f7ab36982cb569027cf831e95ee42ea.tar.gz
haskbox-9d9cfd3c2f7ab36982cb569027cf831e95ee42ea.tar.bz2
haskbox-9d9cfd3c2f7ab36982cb569027cf831e95ee42ea.zip
sort
Diffstat (limited to 'Shuffle.hs')
-rw-r--r--Shuffle.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/Shuffle.hs b/Shuffle.hs
new file mode 100644
index 0000000..d1ad24a
--- /dev/null
+++ b/Shuffle.hs
@@ -0,0 +1,11 @@
+module Shuffle (shuffle) where
+
+import System.Random
+
+shuffle [] = return []
+shuffle xs = do
+ i <- getStdRandom(randomR (0,(length xs)-1))::IO(Int)
+ let (h:rst) = drop i xs
+ oth <- shuffle $ (take i xs) ++ rst
+ return (h:oth)
+