<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PCG, A Better Random Number Generator (Posts about randutils)</title><link>http://www.pcg-random.org/</link><description></description><atom:link href="http://www.pcg-random.org/categories/randutils.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 &lt;a href="mailto:oneill@pcg-random.org"&gt;M.E. O'Neill&lt;/a&gt; </copyright><lastBuildDate>Sat, 10 Jan 2026 05:57:58 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Ease of Use without Loss of Power</title><link>http://www.pcg-random.org/posts/ease-of-use-without-loss-of-power.html</link><dc:creator>M.E. O'Neill</dc:creator><description>&lt;div&gt;&lt;p&gt;To the extent that anyone cares about C++11's random-number facility at all, the C++ community is polarized between two views—one that likes it, and one that hates it.&lt;/p&gt;
&lt;p&gt;The two views are basically these:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It's amazingly elegant, a shining example of &lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;separation of concerns&lt;/a&gt;.  Pseudo-random engines, random distributions, seeding techniques, and entropy sources are all quite different things.  C++11 creates a pluggable and extensible architecture that allows for new RNGs, new custom distributions, and so forth.  It's comprehensive and flexible.&lt;/li&gt;
&lt;li&gt;It's horrible to use, feeling unnecessarily &lt;a href="http://en.wikipedia.org/wiki/Overengineering"&gt;overengineered&lt;/a&gt;.  To do even the simplest task requires significant boilerplate.  Things that would be one easy-to-understand line in Python are three or four hard-to-follow lines in C++11.  It's completely unsuitable for beginners, and even seasoned programmers hate it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both camps are right.  But it turns out that we don't need to do very much to fix the situation and (hopefully) leave both camps feeling that they're getting what they want.&lt;/p&gt;
&lt;p&gt;In this post, we'll develop the missing C++11 class that ties all the pieces together, making C++11 random number generators easy to use without abandoning any of their power and flexibility.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.pcg-random.org/posts/ease-of-use-without-loss-of-power.html"&gt;Read more…&lt;/a&gt; (14 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>c++</category><category>C++17-ideas</category><category>randutils</category><category>seeding</category><guid>http://www.pcg-random.org/posts/ease-of-use-without-loss-of-power.html</guid><pubDate>Mon, 04 May 2015 18:37:23 GMT</pubDate></item><item><title>Simple Portable C++ Seed Entropy</title><link>http://www.pcg-random.org/posts/simple-portable-cpp-seed-entropy.html</link><dc:creator>M.E. O'Neill</dc:creator><description>&lt;div&gt;&lt;p&gt;In two recent posts, I've looked at seeding random number generators in in C++11 (looking at &lt;a href="http://www.pcg-random.org/posts/cpp-seeding-surprises.html"&gt;what's wrong with &lt;code&gt;std::seed_seq&lt;/code&gt;&lt;/a&gt; and &lt;a href="http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html"&gt;developing something that avoids those flaws&lt;/a&gt;), but &lt;code&gt;seed_seq&lt;/code&gt; exists as a mechanism to “mix up” entropy that you give it.  You still need to get that entropy from &lt;em&gt;somewhere&lt;/em&gt;.  So where?&lt;/p&gt;
&lt;h3 id="sadly-stdrandom_device-is-not-your-friend"&gt;Sadly &lt;code&gt;std::random_device&lt;/code&gt; Is Not Your Friend&lt;/h3&gt;
&lt;p&gt;The obvious source for external randomness we can use in seeding is &lt;code&gt;std::random_device&lt;/code&gt;.  But as I mentioned in &lt;a href="http://www.pcg-random.org/posts/cpps-random_device.html"&gt;this post&lt;/a&gt;,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It's hard to make &lt;code&gt;std::random_device&lt;/code&gt; conform to the requirements of a seed sequence.&lt;/li&gt;
&lt;li&gt;It's unspecified just how costly this “device” is to read from.&lt;/li&gt;
&lt;li&gt;It may not be nondeterministic at all, rendering it unfit for our purposes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Portable code needs to look to other sources of entropy for RNG seeding.  And even if &lt;code&gt;std::random_device&lt;/code&gt; works well, mixing in entropy from other sources can have a variety of benefits, including performance.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.pcg-random.org/posts/simple-portable-cpp-seed-entropy.html"&gt;Read more…&lt;/a&gt; (14 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>c++</category><category>C++17-ideas</category><category>entropy</category><category>randutils</category><category>seed_seq</category><category>seeding</category><guid>http://www.pcg-random.org/posts/simple-portable-cpp-seed-entropy.html</guid><pubDate>Mon, 04 May 2015 04:37:48 GMT</pubDate></item><item><title>Developing a seed_seq Alternative</title><link>http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html</link><dc:creator>M.E. O'Neill</dc:creator><description>&lt;div&gt;&lt;p&gt;In &lt;a href="http://www.pcg-random.org/posts/cpp-seeding-surprises.html"&gt;my previous post&lt;/a&gt;, I talked about issues with C++11's &lt;code&gt;std::seed_seq&lt;/code&gt;.  As a reminder, the goal of the &lt;code&gt;std::seed_seq&lt;/code&gt; is to generate seed data that can be used to initialize a random number generator.  And to allow it to do its job it needs seed data.  Seed data in, seed data out.  It might seem like a “do nothing” function would be up to the task, but in many situations the seed data you can provide is of variable quality.  Some of it is “good” entropy, which changes often, and some of it is “lower quality” entropy which is more predictable or changes less frequently (e.g., the machine id).  It also may be that the data that changes often (e.g., the time) changes more in the low-order bits than the high-order bits.  So the goal of &lt;code&gt;std::seed_seq&lt;/code&gt; is to mix together the seed data that we provide so that the high-quality and low-quality data is well-mixed.&lt;/p&gt;
&lt;p&gt;In essence, the task that &lt;code&gt;std::seed_seq&lt;/code&gt; does (and thus anything intending to replace it should do) is compute a hash (i.e., a scrambled version) of its input data.  The design of hash functions is often (rightly) considered to be something of a black art, but since the same can be said of designing random number generators and I've already done that, I might as well tackle this problem, too.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html"&gt;Read more…&lt;/a&gt; (20 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>c++</category><category>C++17-ideas</category><category>randutils</category><category>seed_seq</category><category>seeding</category><guid>http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html</guid><pubDate>Fri, 01 May 2015 00:24:01 GMT</pubDate></item></channel></rss>