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

Immutable.Shuffle

Description

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

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.