Более многословно, чем @ TerryDactyl
case class Tup(groupId: String,
id: Int,
name: String,
randomPick: Boolean = false)
val ts = Seq(
Tup("G1", 1, "apple"),
Tup("G1", 2, "orange"),
Tup("G1", 3, "apple"),
Tup("G1", 4, "banana"),
Tup("G1", 5, "apple"),
Tup("G2", 6, "orange"),
Tup("G2", 7, "apple"),
Tup("G2", 8, "apple"),
Tup("G3", 7, "banana"),
Tup("G3", 8, "orange")
)
val grouped = ts.groupBy(_.groupId)
val withChosen = grouped.map{case (_, ts) =>
val l = ts.length
val i = scala.util.Random.nextInt(l)
ts.zipWithIndex.map{ case (tup, idx) =>
if (idx == i) tup.copy(randomPick = true)
else tup
}
}