perfect-vector-shuffle-0.1.1.2: Library for performing vector shuffles
Safe HaskellSafe-Inferred
LanguageHaskell2010

Mutable.Shuffle

Description

This module provides functions to perform shuffles on mutable vectors. The shuffling is uniform amongst all permuations and uses the minimal number of transpositions.

Synopsis

Documentation

shuffle :: forall m a g v. (PrimMonad m, RandomGen g, MVector v a) => v (PrimState m) a -> g -> m g Source #

Perform a shuffle on a mutable vector with a given random generator, returning a new random generator.

This uses the Fisher--Yates--Knuth algorithm

shuffleM :: forall m a v. (PrimMonad m, MonadRandom m, MVector v a) => v (PrimState m) a -> m () Source #

Perform a shuffle on a mutable vector in a monad which has a source of randomness.

This uses the Fisher--Yates--Knuth algorithm

shuffleK :: forall m a v. (PrimMonad m, MonadRandom m, MVector v a) => Int -> v (PrimState m) a -> m () Source #

Shuffle the first k elements of a vector.

maximalCycle :: forall m a g v. (PrimMonad m, RandomGen g, MVector v a) => v (PrimState m) a -> g -> m g Source #

Perform a shuffle on a mutable vector wherein the shuffled indices form a maximal cycle.

This uses the Sattolo algorithm.

maximalCycleM :: forall m a v. (PrimMonad m, MonadRandom m, MVector v a) => v (PrimState m) a -> m () Source #

Perform a shuffle on a mutable vector wherein the shuffled indices form a maximal cycle in a monad with a source of randomness.

This uses the Sattolo algorithm.

derangement :: forall m a g v. (PrimMonad m, RandomGen g, Eq a, MVector v a) => v (PrimState m) a -> g -> m g Source #

Perform a derangement on a mutable 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. (PrimMonad m, MonadRandom m, Eq a, MVector v a) => v (PrimState m) a -> m () Source #

Perform a derangement on a mutable 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