Logo

Programming-Idioms

History of Idiom 11 > diff from v58 to v59

Edit summary for version 59 by programming-idioms.org:
[Elixir] Comment...

Version 58

2016-11-30, 21:34:16

Version 59

2016-11-30, 21:35:05

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
Code
Enum.random(x)
Code
Enum.random(x)
Comments bubble
Much easier implementation, using only one standard function.
Doc URL
http://elixir-lang.org/docs/stable/elixir/Enum.html#random/1
Doc URL
http://elixir-lang.org/docs/stable/elixir/Enum.html#random/1
Demo URL
http://play.elixirbyexample.com/s/f9f0161650
Demo URL
http://play.elixirbyexample.com/s/f9f0161650