Logo

Programming-Idioms

History of Idiom 11 > diff from v63 to v64

Edit summary for version 64 by benbika:
New Haskell implementation by user [benbika]

Version 63

2017-09-01, 18:31:55

Version 64

2018-01-14, 17:27:28

Idiom #11 Pick a random element from a list

List x must be non-empty.

Illustration

Idiom #11 Pick a random element from a list

List x must be non-empty.

Illustration
Extra Keywords
choose
Extra Keywords
choose
Imports
import System.Random (randomRIO)
Code
(l !!) <$> randomRIO (0, length l - 1)