Logo

Programming-Idioms

History of Idiom 11 > diff from v66 to v67

Edit summary for version 67 by hrschueler:
[Scala] Comments in the comments, not the code.

Version 66

2018-04-17, 16:49:18

Version 67

2018-04-17, 16:50:12

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 scala.util.Random
Imports
import scala.util.Random
Code
val x = List(1, 2, 3, 4)
x.apply(Random.nextInt(x.size))
// apply can be called without the name or dot
// x(Random.nextInt(x.size))
Code
val x = List(1, 2, 3, 4)
x.apply(Random.nextInt(x.size))
Comments bubble
apply can be called without the name or dot
x(Random.nextInt(x.size))