Skip to main content

Random vs ThreadLocalRandom vs SecureRandom vs RandomGenerator in Java (When to Use Each)

Which Java random class to use, tested on JDK 25: why two outputs of java.util.Random predict the third, the three range bugs (negative remainder, abs of MIN_VALUE, modulo bias measured at 60% vs 43%), ThreadLocalRandom vs a shared Random, SecureRandom algorithms and the setSeed trap, and the 13 RandomGenerator algorithms. Every output is quoted from a committed file.

Java Parallel Streams: When They’re Slower (JMH Benchmarks and the Common Pool)

Java parallel streams measured on JDK 25 with JMH: a 100-element stream was 9.4x slower in parallel, an unsplittable source lost, ordered limit() cost several times more, and one blocked common pool slowed an unrelated stream 4x. Plus the parallel bugs that return wrong answers with no exception. Every number comes from committed output.