rand() Considered Harmful
aghuttun1 HN recommender · recommended in 1 month, 2019-2025
16K views · 13 years ago · talk · evergreen
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.
It is the standard reference for why rand() is broken in C++ and what to use instead.
1:17:12C++ Seasoning
aghuttun
58K views • 13 years ago
23:12dotGo 2015 - Rob Pike - Simplicity is Complicated
dotconferences
172K views • 10 years ago
39:47How lucky is too lucky?: The Minecraft Speedrunning Dream Controversy Explained
Stand-up Maths
8.4M views • 5 years ago
51:27Google I/O 2012 - Go Concurrency Patterns
Google for Developers
894K views • 14 years ago
1:29:49Going Native 2012 Keynote Stroustrup
savage309
33K views • 14 years ago
1:30:53C++Now 2018: You Can Do Better than std::unordered_map: New Improvements to Hash Table Performance
CppNow
63K views • 8 years ago
1:54:00Can C++ be 10x Simpler & Safer? - Herb Sutter - CppCon 2022
CppCon
277K views • 3 years ago
12:31OSCON 2010: Rob Pike, "Public Static Void"
O'Reilly
119K views • 16 years ago
51:18Lexical Scanning in Go - Rob Pike
GoogleFOSSSydney
162K views • 15 years ago
1:00:40Dmitry Vyukov — Go scheduler: Implementing language with lightweight concurrency
Hydra
47K views • 7 years ago
1:07:00Sydney Golang Meetup - Rob Pike - Go 2 Draft Specifications
Macquarie Group
57K views • 7 years ago
22:29Gopherfest 2015 | Go Proverbs with Rob Pike
The Go Programming Language
317K views • 10 years ago
29:25Rust NYC: Jon Gjengset - Demystifying unsafe code
Rust Programming Language
27K views • 6 years ago
1:33:12De-fragmenting C++: Making Exceptions and RTTI More Affordable and Usable - Herb Sutter CppCon 2019
CppCon
90K views • 7 years ago
0:27Rob Pike about the target group of the Go programming language (golang)
f8C4G86p KbqEFe47
7K views • 6 years ago
1:29:06CppCon 2015: Herb Sutter "Writing Good C++14... By Default"
CppCon
193K views • 11 years ago
1:39:25CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.”
CppCon
149K views • 10 years ago
39:03RustConf 2020 - Closing Keynote by Siân Griffin
Rust Programming Language
10K views • 6 years ago
59:26The Go Programming Language
Google TechTalks
406K views • 16 years ago
54:01Abseil's Open Source Hashtables: 2 Years In - Matt Kulukundis - CppCon 2019
CppCon
22K views • 7 years ago
3 comments from Hacker News
I used it because it was recommended by Stephan T. Lavavej, maintainer of Visual Studio's C++ Standard Library, in his "rand() Considered Harmful" talk, back when <random> was introduced. See 11m30s. ▶ this video
Whenever I see such libraries, the first thing I check out is their PRNG implementation, and this one must be the worst I've seen so far. (The rest of the library is probably quite good, I'm just talking about the PRNG part) The library has one PRNG, and it is the following: tb_spinlock_enter(&g_lock); g_value = (g_value * 10807 + 1) & 0xffffffff; tb_spinlock_leave(&g_lock); Using this is literally worse than using the rand reference implementation. Also, tb_random_range uses a biased and slow implementation with modulo. (see link for the proper way to do this) I might look into adding a proper PRNG implementation, but I'll recommend a few resources: A lesson of what not to do: ▶ this video ("rand() Considered Harmful") Some good modern PRNGs: link , link , link Generating random numbers in a specific range: link
> Here is a short snippet of some abstract C++ code. As you can see, that is a code from the Windows DLL I stopped reading at this point. But, ok, I didn't really. I also noticed the code was quite dated / inopportune: * Has a "X-er" class - which probably shouldn't exist in the first place. * Using raw `delete` and `new` * Using unions instead of std::variant's * Using C library calls instead of `<algorithm>` functions (memset vs std::fill) * Using `rand()` instead of the standard library's facilities (even though it's broken ▶ this video ) So... it's outdated and inelegant C++, regardless of any actual errors.