Boost C++ Libraries: Ticket #3971: basic_random_generator doesn't produce a fully randomized uuid when sizeof(unsigned long) == 4 https://svn.boost.org/trac10/ticket/3971 <p> There is a flaw in basic_random_generator&lt;&gt; (boost/uuid/uuid_generators.hpp, line 366-374) that means it will only generate about 4 billion different values before a collision on the many platforms where sizeof(unsigned long) == 4. </p> <p> On these platforms the first 8 bytes of the uuid are populated with random data, but the contents of the remaining 8 bytes are undefined. </p> <p> In my tests they are populated with repeated data, due to Microsoft's specific implementation for the undefined behaviour of &gt;&gt; when its "right operand is greater than or equal to the length in bits of the promoted left operand." </p> <p> For example, try the following test program with a Win32 build by Visual C++ 9.0 – </p> <pre class="wiki">#include &lt;iostreams&gt; #include &lt;boost/uuid/uuid_generators.hpp&gt; #include &lt;boost/uuid/uuid_io.hpp&gt; int main( int, char*[] ) { std::cout &lt;&lt; boost::uuids::random_generator()() &lt;&lt; std::endl; return 0; } </pre><p> This produced for me: </p> <pre class="wiki">f1633d75-ee94-47b9-ae94-37b9ee9437b9 </pre><p> Or wrapped to show the problem: </p> <pre class="wiki">f1633d75- ee94-47b9- ae94-37b9 ee94 37b9 </pre><p> The simplest patch could be just: </p> <pre class="wiki">370a370 &gt; i=0; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3971 Trac 1.4.3 Dave Abrahams Sun, 21 Mar 2010 14:27:30 GMT severity changed https://svn.boost.org/trac10/ticket/3971#comment:1 https://svn.boost.org/trac10/ticket/3971#comment:1 <ul> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Showstopper</span> </li> </ul> Ticket Andy Tompkins Thu, 01 Apr 2010 01:03:32 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3971#comment:2 https://svn.boost.org/trac10/ticket/3971#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed as suggested in both trunk and merged into release. </p> Ticket