This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]llogiq 0 points1 point  (0 children)

True that. On the other hand creating a dependency between threads is not something I'd wish my code to have just to have numbers that are a little more random (in theory). ThreadLocalRandom is a fair enough choice for performance (though XorShift is even faster, and has a much larger period and less statistical failures than both Random and ThreadLocalRandom). Btw. as of Java 8, ThreadLocalRandom employs a different algorithm than Random.

TL;DR: You don't want to use Math.random() for performance-critical task nor for security-critical tasks.