Skip to content

Instantly share code, notes, and snippets.

@gsimard
Created March 17, 2012 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsimard/2065481 to your computer and use it in GitHub Desktop.
Save gsimard/2065481 to your computer and use it in GitHub Desktop.
More functional way of doing that
var entitiesMap = Map[Int,Entity]()
private val randEntityId = new scala.util.Random(0)
def uniqueEntityId() = {
var id = 0;
do {
id = randEntityId.nextInt()
} while (entitiesMap.contains(id))
id
}
(last (take-while #(contains entitiesMap %) (iterate nextInt 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment