Safe Haskell | Safe-Infered |
---|
AUTHOR
- Dr. Alistair Ward
DESCRIPTION
- Utilities related to random-numbers.
- randomGens :: RandomGen randomGen => randomGen -> [randomGen]
- shuffle :: RandomGen randomGen => randomGen -> [a] -> [a]
- generateSelection :: RandomGen randomGen => randomGen -> [a] -> [a]
- generateSelectionFromBounded :: (RandomGen randomGen, Bounded a, Random a) => randomGen -> [a]
- select :: RandomGen randomGen => randomGen -> [a] -> a
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.
- The resulting list has the same length and constituents as the original; only the order has changed.
- CAVEAT: the implementation zips a list of integers, with the specified polymorphic list, then sorts it, but when identical random integers are generated, the sort-algorithm being stable always return the corresponding items in their original order. The shuffle is therefore imperfect, but on a 64-bit machine, it would need such a large list of items, for the probability of randomly generating two identical integers, to be significant, that sort probably wouldn't return in a reasonable time anyway. Ideally, it would be amended to use an unstable sort-algorithm.
generateSelection :: RandomGen randomGen => randomGen -> [a] -> [a]Source
- Generate an infinite list of items, each 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 items, each randomly selected, from the specified finite list of bounded items.
- Because the selections are made non-destructively, duplicates may be returned.
- E.g.
(generateSelectionFromBounded
.fmap
System.Random.getStdGen) :: IO [Bool]