Skip to content

Instantly share code, notes, and snippets.

@tjdett
Created September 22, 2017 03:33
Show Gist options
  • Save tjdett/3de0dd34e34e713d5bc04eb606c58623 to your computer and use it in GitHub Desktop.
Save tjdett/3de0dd34e34e713d5bc04eb606c58623 to your computer and use it in GitHub Desktop.
Random team pick
import scala.util.Random
import scala.util.Try
import scala.collection.immutable.Stream
object PickRandom extends App {
def picksValid(picksStr: String) =
Try(picksStr.toInt).filter(_ > 0).isSuccess
override def main(args: Array[String]) {
val picksRequired = args.toList match {
case picksStr :: _ if picksValid(picksStr) => picksStr.toInt
case _ => 1
}
val winOptions = Set("Home", "Away")
val winBy = Random.nextInt(30)
val picks = Stream.continually(Random.shuffle(winOptions).head)
.take(picksRequired)
// e.g.
// scala pick_random.scala 3
// 3 Away Away Home
println(s"${winBy} "+picks.mkString(" "))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment