<div dir="ltr">On Thu, Aug 29, 2013 at 9:42 AM, Eric Blake <span dir="ltr"><<a href="mailto:eblake@redhat.com" target="_blank">eblake@redhat.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">On 08/29/2013 10:33 AM, Eric Blake wrote:<br>
>> Since gnulib has a working random_r() function can we just make<br>
>> gnulib replace the boneheaded freebsd impl ?<br>
><br>
> Huh - the glibc man pages state that random_r returns RAND_MAX bits.<br>
> random_r is a glibc extension: POSIX only requires rand(), rand_r(), and<br>
> random(); but even with random(), POSIX has no requirements that it be<br>
> related to RAND_MAX - so the fact that glibc equates random()/random_r()<br>
> with RAND_MAX is also a glibc extension.<br>
><br>
> I guess that means we should't be worrying about RAND_MAX in the first<br>
> place, as it is tied to the (potentially algorithmically weaker) rand(),<br>
> and need not have any bearing on the fact that we already use gnulib's<br>
> random_r().<br>
><br>
> I'll play around with a patch.<br>
<br>
</div>As it is, POSIX recommends the use of drand48() and friends for<br>
multithreaded apps, not random() (where lrand48() would match precisely<br>
with a RAND_MAX of 0x7fffffff); but that's because POSIX lacks<br>
random_r().  But since gnulib lacks [dl]rand48(), I still think libvirt<br>
is still better off sticking with random_r(), and just avoiding the red<br>
herring of a potentially unrelated RAND_MAX.<br>
<div class=""><div class="h5"><br>
--<br>
Eric Blake   eblake redhat com    <a href="tel:%2B1-919-301-3266" value="+19193013266">+1-919-301-3266</a><br>
Libvirt virtualization library <a href="http://libvirt.org" target="_blank">http://libvirt.org</a><br>
<br>
</div></div></blockquote></div><br></div><div class="gmail_extra">This is outside of my expertise at this point, but here is the discussion thread regarding this on a FreeBSD mailing list:<br><br><a href="http://lists.freebsd.org/pipermail/freebsd-current/2013-August/044084.html">http://lists.freebsd.org/pipermail/freebsd-current/2013-August/044084.html</a><br>
<br></div><div class="gmail_extra">Thanks!<br><br></div><div class="gmail_extra">-jgh<br></div><div class="gmail_extra"><br>-- <br><div dir="ltr">Jason Helfman          | FreeBSD Committer<br>jgh@FreeBSD.org     | <a href="http://people.freebsd.org/%7Ejgh" target="_blank">http://people.freebsd.org/~jgh</a>  | The Power to Serve<br>
</div>
</div></div>