Created
May 19, 2014 17:51
-
-
Save darkfrog26/36b55782dfa92282fcb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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