<div dir="ltr">Any ideas when Foundation on Linux will support arc4random_uniform? This is kind of an important function.<div>There doesn&#39;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><br></div><div>Has anyone come up with a better solution to get a true uniform distribution that isn&#39;t super messy?</div><div> <div><div>import Foundation</div><div><br></div><div>#if os(Linux)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>import Glibc</div><div>#endif</div></div><div><br></div><div><br></div><div><div>public func random_uniform(range: Int) -&gt; Int {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>guard range &gt; 0 else { return 0 }</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>#if os(Linux)</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>  return Int(random()) % range</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>#else</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">          </span>return Int(arc4random_uniform(UInt32(range)))</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>#endif</div><div>}</div></div><div><br></div></div><div><br></div><div>Thanks, Ed</div></div></div>