app

Safe Haskell None
Language Haskell2010

Random

Description

Library functions about randomness

Synopsis

Documentation

pick :: RandomGen r => r -> [a] -> (Maybe a, r) #

Pick one element at random from the second argument, using the given random generator. Returns the updated generator and the picked element (being Just if the list non-empty). See oneof for a variant of this function.

pickM #

Arguments

:: RandomGen r  
=> MonadState r m  
=> [a]

The elements from which something must be picked

-> m (Maybe a)  

Returns a random element from the list, if it is non empty. If you a non-empty list at hand, call oneof instead.

shuffle :: RandomGen r => r -> [a] -> ([a], r) #

Shuffles the second argument with the random generator. Returns the shuffle and the updated generator.

shuffleM :: RandomGen r => MonadState r m => [a] -> m [a] #

Shuffles the given list with a random generator

oneof #

Arguments

:: RandomGen r  
=> MonadState r m  
=> NonEmpty a

The elements from which something must be picked

-> m a  

Returns a random element from the list. If you have a possibly empty list at hand, call pickM instead.

roll #

Arguments

:: RandomGen r  
=> MonadState r m  
=> Random p  
=> Ord p  
=> p

The minimum element

-> p

The maximum element

-> m p  

'roll min max' returns a value between min (included) and max (included). 'min <= max' should hold.