toolshed-0.15.0.0: Utilities used by other packages.

Safe HaskellSafe-Inferred

ToolShed.System.Random

Contents

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
Utilities related to random-numbers.

Synopsis

Functions

randomGens :: RandomGen randomGen => randomGen -> [randomGen]Source

Constructs an infinite list of independent random-generators.

shuffle :: RandomGen randomGen => randomGen -> [a] -> [a]Source

  • Shuffles the specified finite list, using the Fisher-Yates algorithm; http://en.wikipedia.org/wiki/Fisher-Yates_shuffle.
  • The resulting list has the same length and constituents as the original; only the order has changed.
  • The input list is traversed, but the items aren't evaluated.

generateSelection :: RandomGen randomGen => randomGen -> [a] -> [a]Source

  • Generate an infinite list of items, each independently randomly selected from the specified finite list.
  • CAVEAT: because the selections are made non-destructively, duplicates may be returned; cf. shuffle.

generateSelectionFromBounded :: (RandomGen randomGen, Bounded a, Random a) => randomGen -> [a]Source

  • Generate an infinite list of data, each independently selected random instances of the specified bounded type.
  • E.g. (generateSelectionFromBounded fmap System.Random.getStdGen) :: IO [Bool] .

select :: RandomGen randomGen => randomGen -> [a] -> aSource

Return a randomly selected element from the specified list.