5 ms·
This is interesting from a pedantic point of view. From an engineering point of view, I'd not look very kindly on the person who checked in a random number alg
by baggy_trough 6y ago
This is interesting from a pedantic point of view. From an engineering point of view, I'd not look very kindly on the person who checked in a random number algorithm that required 300 lines of comments to understand. There would have to be an awfully good reason to use it, and here there really isn't.
- ggm 6y agoDivision is expensive and requires out calls in chips without an integrated FPU. Kernels require fast, tractable random numbers early in boot time. The Unix kernel resident rng had a lot of work done on it over the years for a very small fragment of code. The algorithms come from mathematicians. Maybe, they're doing it for innate satisfaction of things done in the integer number field?
- shmageggy 6y agoPlenty of algorithms require a lot of background knowledge to understand. Should we ban crypto algorithms because they require hundreds of lines of comments explaining elliptic curves? Of course not, we just assume people can read the papers.
- detaro 6y ago> There would have to be an awfully good reason to use it, and here there really isn't. Crypto primitives generally come with very good reasons why we want to use them (and even among them, understandability at least of some aspects of them is highly valued). The GP comment specifically challenges that this trade-off is not the case here. "Should we ban crypto algorithms" is attacking an argument they haven't made.
- edflsafoiewq 6y agoI think any algorithm (even the usual one with division) would take hundreds of lines of comments if written in this style. There are thirty lines just to explain -x % x. Myself, I'd rather see uint64_t t = -s % s; // = (2^64 - s) % s = 2^64 % s
- tuananh 6y agoyep, this is a lot faster to digest and still juts as clear
- klyrs 6y agoYou'll love my approach: exactly one comment with a reference to the original paper. Maybe with another line explaining that the reference pseudocode and implementation differ in dropping the 2^64 But that approach would fail the readability challenge, I think (hope)
- etangent 6y agoRandom number generation powers many quantitative applications that perform expensive Monte Carlo experiments and like. Even minor speed ups here are very interesting IMO.