Being a quick sketch combining <chrono> and <random> functionality, with cryptarithmetic interludes… At CppCon this year there were several good talks about randomness and time calculations in C++. On randomness: Walter Brown’s What C++ Programmers Need to Know About Header <random> and Cheinan Marks’ I Just Wanted a Random Integer! were both excellent talks. And… Continue reading CHRONO + RANDOM = ?
An algorithmic sketch: inplace_merge
One of the things I like to do in my spare time is study the STL algorithms. It is easy to take them for granted and easy, perhaps, to imagine that they are mostly trivial. And some are: I would think that any decent interview candidate ought to be able to write find correctly. (Although… Continue reading An algorithmic sketch: inplace_merge
ELI5: monoids
(Resulting from my claim that “a child of 8 can understand monoids…”) Wikipedia says: “In abstract algebra, a branch of mathematics, a monoid is an algebraic structure with a single associative binary operation and an identity element.” Wolfram says: A monoid is a set that is closed under an associative binary operation and has an… Continue reading ELI5: monoids
Lameness Explained
OK, more than one person wanted explanations of The C++ <random> Lame List, so here are some of my thoughts, if only to save people searching elsewhere. Calling rand() is lame because it’s an LCG with horrible randomness properties, and we can do better. And if you’re not calling rand(), there’s no reason to call… Continue reading Lameness Explained
The C++ <random>
Lame List
Network programmers of a certain age may remember the Windows Sockets Lame List. I previously wrote a short “don’t-do-that-do-this” guide for modern C++ randomness, and I was recently reading another Reddit exchange featuring STL, author of many parts of Microsoft’s STL implementation, when it struck me that use of C++ <random> needs its own lame… Continue reading The C++ <random>
Lame List
Amaze your friends, and confound your enemies!
When I was young, I read lots of books with titles (or at least subheadings) along the lines of, “Amaze Your Friends and Confound Your Enemies” – a lot of them were filled with tricks and oddities like the Birthday Paradox, or the old saw about the elephant from Denmark. It turns out that if… Continue reading Amaze your friends, and confound your enemies!
Compile-time RNG tricks
(Start at the beginning of the series – and all the source can be found in my github repo) Compile-time random number generation is quite useful. For instance, we could generate GUIDs (version 4 UUIDs): namespace cx { struct guid_t { uint32_t data1; uint16_t data2; uint16_t data3; uint64_t data4; }; template constexpr guid_t guidgen() {… Continue reading Compile-time RNG tricks
Compile-time counters, revisited
(Start at the beginning of the series – and all the source can be found in my github repo) Some time ago I read a blog post showing how to make a compile-time counter: a constexpr function that would return monotonically increasing integers. When I first read it I didn’t really take the time to… Continue reading Compile-time counters, revisited
More string hashing with C++11 constexpr
(Start at the beginning of the series – and all the source can be found in my github repo) So FNV1 was easy, and Murmur3 wasn’t too much harder; for a challenge and to see how far I could go, I decided to try to compute an MD5 string hash using C++11 constexpr. This was… Continue reading More string hashing with C++11 constexpr
C++11 compile-time string hashing
(Start at the beginning of the series – and all the source can be found in my github repo) Now that I was used to writing C++11-style constexpr, I decided to try some compile-time string hashing. It turns out that FNV1 is very easy to express in a move-down-the-string recursive style: namespace detail { constexpr… Continue reading C++11 compile-time string hashing