rand() Considered Harmful
What it is
Stephan T. Lavavej's GoingNative 2013 talk explaining why calling rand() and using rand() % 100 is bad in C++, and how the C++11 <random> header does the job properly.
Why Hacker News recommends it
It is the standard reference for why rand() is broken in C++ and what to use instead.
- 1 people recommended it
- 1 different months
- 0 strong recommendations
- first 2019, last 2025
What HN commenters said
“A lesson of what not to do: ("rand() Considered Harmful")”
Lesson on what not to do with rand().
camel-cdr, 2022-05 · Recommendation · in “Show HN: A glib-like multi-platform C library”
Excerpts from Hacker News comments, linked to the originals. Summaries and labels were written by a language model from those comments.
Topics: c++, random, stl, c++11, goingnative
Also recommended by the same people
demoRobust-first computing: Demon Horde Sort (full version)Dave Ackley · 3 HN recommenders · 2015–2023
talkCppCon 2015: Andrei Alexandrescu “std::allocator...”CppCon · 7 HN recommenders · 2017–2025
talkLexical Scanning in Go - Rob PikeGoogleFOSSSydney · 13 HN recommenders · 2012–2025
talkCppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”CppCon · 9 HN recommenders · 2018–2026
talkRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine WestRust Programming Language · 9 HN recommenders · 2018–2023
talkCppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”CppCon · 13 HN recommenders · 2016–2024
talkIdeas about a new programming language for games.Jonathan Blow · 7 HN recommenders · 2014–2025
talkCppCon 2014: Mike Acton "Data-Oriented Design and C++"CppCon · 9 HN recommenders · 2015–2026