Skip to content

Instantly share code, notes, and snippets.

@darkfrog26
Created May 19, 2014 17:51
Show Gist options
  • Save darkfrog26/36b55782dfa92282fcb0 to your computer and use it in GitHub Desktop.
Save darkfrog26/36b55782dfa92282fcb0 to your computer and use it in GitHub Desktop.
import java.util.UUID
import scala.util.Random
import java.util.concurrent.ThreadLocalRandom
import scala.annotation.tailrec
/**
* @author Matt Hicks <matt@outr.com>
*/
object Unique {
private val r = new Random(ThreadLocalRandom.current())
@tailrec
final def apply(): String = new UUID(r.nextLong(), r.nextLong()).toString.replace("-", "") match {
case s if !s.charAt(0).isDigit => s
case s => apply()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment