Logo

Programming-Idioms

History of Idiom 11 > diff from v64 to v65

Edit summary for version 65 by benbika:
[Haskell] no return needed

Version 64

2018-01-14, 17:27:28

Version 65

2018-01-14, 17:28:53

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
Imports
import System.Random (randomRIO)
Code
return.(x!!)=<<System.Random.randomRIO(0,length x-1)
Code
(l !!) <$> (randomRIO (0, length l))