<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">drand48 is a small LCG and I think it also needs to be seeded before you use it with srand48; otherwise it’ll give the same sequence each time.<div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On May 24, 2017, at 08:15, Edward Connell &lt;<a href="mailto:ewconnell@gmail.com" class="">ewconnell@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thank you for all the feedback and options. In further investigation, I also ran across the family of xx48 rngs, which appear to be on both platforms. They claim to be uniformly distributed.<div class=""><br class=""></div><div class=""><span style="font-family: 'Times New Roman';" class="">drand48, erand48, jrand48, lcong48, lrand48, mrand48, nrand48, seed48, srand48</span><br class=""></div><div class=""><span style="font-family: 'Times New Roman';" class=""><br class=""></span></div><div class=""><font face="Times New Roman" class=""><a href="http://pubs.opengroup.org/onlinepubs/007908775/xsh/drand48.html" class="">http://pubs.opengroup.org/onlinepubs/007908775/xsh/drand48.html</a></font><br class=""></div><div class=""><font face="Times New Roman" class=""><br class=""></font></div><div class=""><font face="Times New Roman" class="">Any reason not to use one of these instead?</font></div><div class=""><font face="Times New Roman" class=""><br class=""></font></div><div class=""><font face="Times New Roman" class="">Thanks, Ed</font></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, May 23, 2017 at 3:18 AM, Jens Persson <span dir="ltr" class="">&lt;<a href="mailto:jens@bitcycle.com" target="_blank" class="">jens@bitcycle.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Here's a stripped down verison of my implementation of the Xoroshiro128+ PRNG:<div class=""><a href="https://gist.github.com/anonymous/527602968812f853d6147aea8c66d660" target="_blank" class="">https://gist.github.com/<wbr class="">anonymous/<wbr class="">527602968812f853d6147aea8c66d6<wbr class="">60</a></div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">/Jens</div><div class=""><br class=""></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, May 22, 2017 at 11:21 PM, Jens Persson <span dir="ltr" class="">&lt;<a href="mailto:jens@bitcycle.com" target="_blank" class="">jens@bitcycle.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Sorry for the premature send ...<div class="">Here is the site: <a href="http://xoroshiro.di.unimi.it/" target="_blank" class="">http://xoroshiro.di.unimi.it</a><br class=""></div><div class="">There is also a section there about "generating uniform doubles in unit interval" which is worth reading.</div><div class="">And here's how to get uniform floating point values in the range [0, 1) from various (supposedly) random bit patterns:</div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt64</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> shifts: </span><span style="font-variant-ligatures:no-common-ligatures" class="">UInt64</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> = 63 - </span><span style="font-variant-ligatures:no-common-ligatures" class="">UInt64</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">significandBitCo<wbr class="">unt</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v &gt;&gt; shifts) * (.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">ulpOfOne</span><span style="font-variant-ligatures:no-common-ligatures" class="">/2)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt32</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v) + 0.5) / (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt32</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">max</span><span style="font-variant-ligatures:no-common-ligatures" class="">) + 1.0)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt16</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v) + 0.5) / (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt16</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">max</span><span style="font-variant-ligatures:no-common-ligatures" class="">) + 1.0)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt8</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v) + 0.5) / (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Double</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt8</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">max</span><span style="font-variant-ligatures:no-common-ligatures" class="">) + 1.0)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt64</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> shifts: </span><span style="font-variant-ligatures:no-common-ligatures" class="">UInt64</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> = 63 - </span><span style="font-variant-ligatures:no-common-ligatures" class="">UInt64</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">significandBitCou<wbr class="">nt</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Float</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v &gt;&gt; shifts) * (.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">ulpOfOne</span><span style="font-variant-ligatures:no-common-ligatures" class="">/2)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt32</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> shifts: </span><span style="font-variant-ligatures:no-common-ligatures" class="">UInt32</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> = 31 - </span><span style="font-variant-ligatures:no-common-ligatures" class="">UInt32</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">Float</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">significandBitCou<wbr class="">nt</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Float</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v &gt;&gt; shifts) * (.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">ulpOfOne</span><span style="font-variant-ligatures:no-common-ligatures" class="">/2)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt16</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> a = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Float</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v) + 0.5</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> b = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Float</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt16</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">max</span><span style="font-variant-ligatures:no-common-ligatures" class="">) + 1.0</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = a / b</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(unitRange v: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt8</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> a = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Float</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v) + 0.5</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> b = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">Float</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">UInt8</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)" class="">max</span><span style="font-variant-ligatures:no-common-ligatures" class="">) + 1.0</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = a / b</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">You will get a very fast and good quality prng using xoroshiro, converting to unit range floating point and then back to uniform range int if you want to, much much faster than arc4random.</span></div><span class="m_2744094100351814297HOEnZb"><font color="#888888" class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">/Jens</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div></font></span></div></div><div class="m_2744094100351814297HOEnZb"><div class="m_2744094100351814297h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, May 22, 2017 at 11:17 PM, Jens Persson <span dir="ltr" class="">&lt;<a href="mailto:jens@bitcycle.com" target="_blank" class="">jens@bitcycle.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Check out the generators (especially xoroshiro) on this site:</div><div class="m_2744094100351814297m_-8876985151572480040HOEnZb"><div class="m_2744094100351814297m_-8876985151572480040h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, May 22, 2017 at 6:54 PM, Saagar Jha via swift-users <span dir="ltr" class="">&lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class="">Saagar Jha</div>

</div>
<br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On May 22, 2017, at 08:44, Edward Connell via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986Apple-interchange-newline"><div class=""><div dir="ltr" class="">Any ideas when Foundation on Linux will support&nbsp;arc4random_uniform? This is kind of an important function.<div class="">There doesn't seem to be any decent substitute without requiring the installation of libbsd-dev, which turns out to be messy. Currently I am doing this, but glibc random with mod does not produce good quality numbers, due to modulo bias.</div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Modulo bias is easy to deal with, though, if you force random to produce a range that is a multiple of the range that you’re trying to produce:</div><span class=""><div class=""><br class=""></div><div class="">guard range &gt; 0 else { return 0 }</div></span><div class="">var random: Int</div><div class="">repeat {</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986Apple-tab-span" style="white-space:pre-wrap">        </span>random = Int(random())</div><div class="">} while(random &gt;&nbsp;LONG_MAX / range * range)</div><div class="">return random % range</div><br class=""><blockquote type="cite" class=""><div class=""><span class=""><div dir="ltr" class=""><div class=""><div class=""><br class=""></div><div class="">Has anyone come up with a better solution to get a true uniform distribution that isn't super messy?</div><div class="">&nbsp;<div class=""><div class="">import Foundation</div><div class=""><br class=""></div><div class="">#if os(Linux)</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>import Glibc</div><div class="">#endif</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">public func random_uniform(range: Int) -&gt; Int {</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>guard range &gt; 0 else { return 0 }</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>#if os(Linux)</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> &nbsp;return Int(random()) % range</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>#else</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986gmail-Apple-tab-span" style="white-space:pre-wrap">          </span>return Int(arc4random_uniform(UInt32(<wbr class="">range)))</div><div class=""><span class="m_2744094100351814297m_-8876985151572480040m_2482228478634656447m_1244819390521955986gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>#endif</div><div class="">}</div></div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">Thanks, Ed</div></div></div></span><span class="">
______________________________<wbr class="">_________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-users</a><br class=""></span></div></blockquote></div><br class=""></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-users</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>