We're updating the issue view to help you get more done. 

ThreadLocalRandom instead of Math/random

Description

The standard Math.random() is thread-safe through being declared as a synchronized static method.

The patch uses java.util.concurrent.ThreadLocalRandom which actually seems to be two times faster than the ordinary Math.random() in a simple single threaded criterium.core/bench:

The reason I investigated the function at all was to be sure random-number generation was not a bottleneck when performance testing multithreaded load generation.

If necessary, one could of course make a conditional declaration (like in fj-reducers) based on the existence of the class java.util.concurrent.ThreadLocalRandom, if Clojure 1.7 is to be compatible with Java versions < 1.7

Environment

Requires Java >=1.7!

Status

Assignee

Unassigned

Reporter

Linus Ericsson

Labels

Approval

Vetted

Patch

Code

Fix versions

Affects versions

Release 1.7

Priority

Minor