Skip to content

Instantly share code, notes, and snippets.

@emopers
Created April 8, 2016 19:43
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 emopers/47aff18d51afcbc38b938e2af0c3869b to your computer and use it in GitHub Desktop.
Save emopers/47aff18d51afcbc38b938e2af0c3869b to your computer and use it in GitHub Desktop.
Improve random number generation to reduce contention
In RealTimePlayer.java, Math.random() is used for random number generation.
According to Java API (Link: http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#random--),
it's suggested that each thread has their own random number generator to reduce contention.
The increasing in contention might have a significant effect since the random number generation is
in Thread implementation.
This pull request improved the condition by replacing Math.random() with Random.nextInt().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment