Tag

ThreadLocalRandom

2 views collected around this technical thread.

Cognitive Technology Team
Cognitive Technology Team
May 3, 2023 · Fundamentals

Correct Usage of ThreadLocalRandom and the Predictable Random Number Pitfall in Java

The article explains why ThreadLocalRandom should not be stored in a static field, demonstrates how using ThreadLocalRandom.current().nextX(...) avoids predictable random numbers, compares behavior between JDK 11 and JDK 19, and provides the proper usage pattern with code examples.

ConcurrencyJDK11JDK19
0 likes · 3 min read
Correct Usage of ThreadLocalRandom and the Predictable Random Number Pitfall in Java
Sohu Tech Products
Sohu Tech Products
Apr 27, 2022 · Backend Development

Why Using Fixed Seeds with Java Random Prints "Hello World"

This article explains how seeding Java's Random with specific integer values generates deterministic character sequences that spell "hello world", walks through the underlying ASCII conversion, shows code examples, and discusses related Java source quirks and seed‑search techniques.

Code ExplanationHello WorldJava
0 likes · 10 min read
Why Using Fixed Seeds with Java Random Prints "Hello World"
Top Architect
Top Architect
Jan 1, 2022 · Backend Development

Understanding ThreadLocalRandom and Unsafe in Java: Performance, Implementation, and Pitfalls

This article examines Java's Random performance limitations, explains how ThreadLocalRandom leverages the Unsafe class for per‑thread seed management, analyzes the underlying native methods, discusses safety concerns and memory layout, and shares practical code examples and insights for high‑concurrency applications.

ConcurrencyJDKJava
0 likes · 10 min read
Understanding ThreadLocalRandom and Unsafe in Java: Performance, Implementation, and Pitfalls
Ops Development Stories
Ops Development Stories
Dec 17, 2021 · Backend Development

Boost Java Concurrency Performance with ThreadLocalRandom: Deep Dive & Code

This article explains how ThreadLocalRandom in JDK7 improves multithreaded random number generation, compares it with Random and Math.random(), analyzes the underlying linear congruential algorithm, and provides practical code examples for high‑performance Java applications.

ConcurrencyJavaPerformance
0 likes · 9 min read
Boost Java Concurrency Performance with ThreadLocalRandom: Deep Dive & Code
macrozheng
macrozheng
Jun 25, 2021 · Fundamentals

Mastering Java Random Number Generation: Random, ThreadLocalRandom, SecureRandom & Math

This article reviews four Java random number generation techniques—Random, ThreadLocalRandom, SecureRandom, and Math.random()—detailing their usage, underlying algorithms, thread‑safety, performance trade‑offs, and appropriate scenarios, helping developers choose the right tool for their applications.

ConcurrencyJavaMath.random
0 likes · 15 min read
Mastering Java Random Number Generation: Random, ThreadLocalRandom, SecureRandom & Math