Skip to content

Instantly share code, notes, and snippets.

@ericpony
Last active August 29, 2015 14:01
Show Gist options
  • Save ericpony/e47195006f766f430af8 to your computer and use it in GitHub Desktop.
Save ericpony/e47195006f766f430af8 to your computer and use it in GitHub Desktop.
I expect the following code to yield a random permutation of {1,2,3,4}. However, it always outputs 1,2,3,4 in order. What's wrong with it?
(1 to 4).foreach(i => {
val f = scala.actors.Futures.future {
Thread.sleep(scala.util.Random.nextInt(10) * 500)
println(i)
}
f()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment