module Util.Random where
import qualified System.Random.Shuffle as Shuffle
import qualified Util.Num as Num
shuffle :: [a] -> [Int] -> [a]
shuffle :: forall a. [a] -> [Int] -> [a]
shuffle [a]
xs = forall a. [a] -> [Int] -> [a]
Shuffle.shuffle [a]
xs forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [Int]
mangle
where
mangle :: [Int] -> [Int]
mangle [Int]
rs = [forall a. Real a => a -> a -> a -> a
Num.restrict Int
0 (Int
lenforall a. Num a => a -> a -> a
+Int
1forall a. Num a => a -> a -> a
-Int
i) Int
v | (Int
i, Int
v) <- forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] (forall a. Int -> [a] -> [a]
take Int
len [Int]
rs)]
len :: Int
len = forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs forall a. Num a => a -> a -> a
- Int
1