{- |
Description: Random permutation of a list
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Maintainer: dev@chungyc.org

Some solutions to "Problems.P25" of Ninety-Nine Haskell "Problems".
-}
module Solutions.P25 (randomPermute) where

-- The implementation for problem 23 also happens to solve this problem.
-- Note that this does *not* import Problems.P23,
-- since the problem does not specify that the order is random.
import           Solutions.P23
import           System.Random

-- | Generate a random permutation of the elements of a list.
randomPermute :: RandomGen g => [a] -> g -> ([a], g)
randomPermute :: forall g a. RandomGen g => [a] -> g -> ([a], g)
randomPermute [a]
xs = [a] -> Int -> g -> ([a], g)
forall g a. RandomGen g => [a] -> Int -> g -> ([a], g)
randomSelect [a]
xs ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs)