{"by":"GeorgeHaldane","descendants":58,"id":44157584,"kids":[44159902,44161561,44160033,44159058,44162214,44161589,44158632,44158824,44161325,44160011,44163680,44158934,44160211],"score":52,"text":"Morning HN.<p>Random number generation feels is a somewhat underrepresented topic in the C++ realm. There is a lot of questionable info about it found online and even the standard library is quite behind the times in terms of it&#x27;s algorithms. It suffers from trying to accommodate sometimes impractical standard requirements and has several ways of getting significantly bad statistical results. This leaves a lot easily achievable performance &amp; quality on the table.<p>So, being a mathematician who mostly works with stochastic models and wants these models to run fast and well, I embarked on a journey of trying to summarize &quot;what is good and what is bad&quot; and implement the &quot;best stuff there currently is&quot;.<p>Thankfully, the design of C++ &lt;random&gt; is quite flexible and easy to extend. With some cleanup, generalization and compile-time logic all the different algorithms can be wrapped in a generic standard-compatible API.<p>A result of this work is single-header RNG library which has:<p><pre><code>  - &lt;random&gt;-compatible generators (PRNGSs) with 3x-6x better performance\n  - Cryptographically secure generators (CSPRNGs)\n  - Faster uniform &#x2F; normal distributions that produce same sequences on every platform\n  - Quick approximations of some non-linear distributions\n  - More reliable entropy sources that std::random_device()\n  - rand()-like API for when we just want random numbers without the boilerplate of proper a &lt;random&gt; setup\n</code></pre>\nEffectively all of this gets us 2x-8x speedups on many workloads while producing even better statistical quality.<p>Don&#x27;t think there is anything else like it, so I would like to showcase the result here and hear some opinions on its improvement:<p><a href=\"https:&#x2F;&#x2F;github.com&#x2F;DmitriBogdanov&#x2F;UTL&#x2F;blob&#x2F;master&#x2F;docs&#x2F;module_random.md\">https:&#x2F;&#x2F;github.com&#x2F;DmitriBogdanov&#x2F;UTL&#x2F;blob&#x2F;master&#x2F;docs&#x2F;modul...</a><p>For those interested, there is a more detailed rundown of all the quirks of this topic at end of the docs, might prove an interesting read.","time":1748862585,"title":"Show HN: Fast Random Library for C++17","type":"story","url":"https://github.com/DmitriBogdanov/UTL/blob/master/docs/module_random.md"}