Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides functions to perform shuffles on immutable vectors. The shuffling is uniform amongst all permuations and performs the minimal number of transpositions.
Synopsis
- shuffle :: forall a g v. (RandomGen g, Vector v a) => v a -> g -> (v a, g)
- shuffleM :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => v a -> m (v a)
- shuffleK :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => Int -> v a -> m (v a)
- sampleWithoutReplacement :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => Int -> v a -> m (v a)
- maximalCycle :: forall a g v. (RandomGen g, Vector v a) => v a -> g -> (v a, g)
- maximalCycleM :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => v a -> m (v a)
- derangement :: forall a g v. (Eq a, RandomGen g, Vector v a) => v a -> g -> (v a, g)
- derangementM :: forall m a v. (Eq a, MonadRandom m, PrimMonad m, Vector v a) => v a -> m (v a)
Documentation
shuffle :: forall a g v. (RandomGen g, Vector v a) => v a -> g -> (v a, g) Source #
Perform a shuffle on an immutable vector with a given random generator returning a shuffled vector and a new generator.
This uses the Fisher--Yates--Knuth algorithm.
shuffleM :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => v a -> m (v a) Source #
Perform a shuffle on an input immutable vector in a monad which has a source of randomness.
This uses the Fisher--Yates--Knuth algorithm.
shuffleK :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => Int -> v a -> m (v a) Source #
Perform a shuffle on the first k elements of a vector in a monad which has a source of randomness.
sampleWithoutReplacement :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => Int -> v a -> m (v a) Source #
Get a random sample of k elements without replacement from a vector.
maximalCycle :: forall a g v. (RandomGen g, Vector v a) => v a -> g -> (v a, g) Source #
Perform an in-place shuffle on an immutable vector wherein the shuffled indices form a maximal cycle.
This uses the Sattolo algorithm.
maximalCycleM :: forall m a v. (MonadRandom m, PrimMonad m, Vector v a) => v a -> m (v a) Source #
Perform an in-place shuffle on an immutable vector wherein the shuffled indices form a maximal cycle in a monad with a source of randomness.
This uses the Sattolo algorithm.
derangement :: forall a g v. (Eq a, RandomGen g, Vector v a) => v a -> g -> (v a, g) Source #
Perform an in-place derangement on an immutable vector with a given random generator, returning a new random generator.
Note: It is assumed the input vector consists of distinct values.
This uses the "early refusal" algorithm.
derangementM :: forall m a v. (Eq a, MonadRandom m, PrimMonad m, Vector v a) => v a -> m (v a) Source #
Perform an in-place derangement on an immutable vector in a monad which has a source of randomness.
Note: It is assumed the input vector consists of distinct values.
This uses the "early refusal" algorithm.