Skip to content

Instantly share code, notes, and snippets.

@OlegEfrem
Created February 15, 2015 18:28
Show Gist options
  • Save OlegEfrem/02a7ed565619588ab4ba to your computer and use it in GitHub Desktop.
Save OlegEfrem/02a7ed565619588ab4ba to your computer and use it in GitHub Desktop.
Random quote from URL file
import scala.collection.mutable.ListBuffer
import scala.io.Source
import scala.util.Random
val sourceLines = Source.fromURL("http://www.coverfire.com/files/quotes.txt","UTF-8").getLines()
val quotes = new ListBuffer[String]
sourceLines.reduceLeft((a,b) => if (b.nonEmpty) a + " " + b else {quotes.+=(a.trim); ""})
val randomQuote = quotes.apply(Random.nextInt(quotes.size))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment