Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Integer division is slow (kristerw.blogspot.com)
19 points by ingve on May 16, 2017 | hide | past | favorite | 2 comments


Your code

    std::random_device entropySource;
    std::mt19937 randGenerator(entropySource());
does not properly seed a mt19937. To copy a comment I made just two weeks ago (this error is a direct result of <random>'s poor design),

It is unfortunate how people keep trying to use `std::mt19937` and, unsurprisingly given how hard it is to use, how they (almost)[0] inevitably fail. Do yourself a favour and use a randomness library that doesn't hate you[1], is simple to seed correctly[2], produces decent quality randomness[3], isn't horribly bloated[4] and has more features[5] to boot. It's 2017. Let the Mersenne Twister die.

[0]: https://codereview.stackexchange.com/q/114066/40768

[1]: http://www.pcg-random.org/

[2]: http://www.pcg-random.org/posts/cpps-random_device.html

[3]: http://www.pcg-random.org/paper.html

[4]: https://cs.stackexchange.com/q/50059/16408

[5]: http://www.pcg-random.org/using-pcg-cpp.html#extra-features


How come the optimizer doesn't figure out theIntDist is constant if it's declared outside the loop? Given that the function is templated, it should have access to its internals, and so have all the information needed to do constant propagation, no?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: