<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 21, 2016, at 1:24 PM, Jens Alfke via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 21, 2016, at 1:00 PM, Erica Sadun via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;">* In terms of cross-platform random numbers, there are any number of third party libraries and you can use rand() on many platforms</div></div></blockquote></div><br class=""><div class="">rand() is deprecated because it uses a poor algorithm that doesn’t provide enough randomness. From the random(3) man page:</div><div class=""><br class=""></div><div class=""> The random() and srandom() functions have (almost) the same calling<br class=""> sequence and initialization properties as the rand(3) and srand(3) func-<br class=""> tions. The difference is that <b class="">rand(3) produces a much less random<br class=""> sequence -- in fact, the low dozen bits generated by rand go through a<br class=""> cyclic pattern.</b> All of the bits generated by random() are usable. For<br class=""> example, `random()&01' will produce a random binary value.<br class=""><br class=""></div><div class="">I’d forgotten that random()s sidekick function srandomdev() seeds the RNG with a cryptographic source of entropy, making it usable for secure purposes. So these would be good functions to implement a Swift RNG with.</div></div></div></blockquote><br class=""></div><div>Another important thing arc4random_uniform provides is a uniform distribution between 0 and an arbitrary upper bound. Naively constraining the output of random() by using '%' will give you a biased result if the bound isn't a power of 2.</div><div><br class=""></div><div>-Joe</div></body></html>