Skip to content

Instantly share code, notes, and snippets.

@oc
Created December 1, 2009 00:28
Show Gist options
  • Save oc/245931 to your computer and use it in GitHub Desktop.
Save oc/245931 to your computer and use it in GitHub Desktop.
val chars = "abcdefghijklmnopqrstuvwxyz"
val rand = new scala.util.Random(System.currentTimeMillis)
def randChar(upperCase:Boolean) = {
val ch = chars(rand.nextInt(chars.length - 1))
if (upperCase) ch.toUpperCase else ch
}
scala> "Ole Christian Rynning".split(" ").map(_.map(ch => randChar(ch.isUpperCase)).mkString).mkString(" ")
res0: String = Aee Ochbivgjm Vgxwuuc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment