<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 06/20/2012 05:00 PM, Bob Ippolito wrote:
<blockquote
cite="mid:CACwMPm_UW=hjRgPGhYYsQAYCw1dXi6xyev1TfJ0aBAfhTjnZ+w@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
The random module is *very* weak, it has less than 48 bits of
state (Wichmann-Hill 1982). It doesnt really generate results
appropriate for double precision float, and it fails modern test
suites for PRNGs, so it's basically unsuitable for most modern
applications. Also, I haven't looked at Yaws' implementation but
the random module only ensures that you have a good seed if you
are using the process dictionary version of the API, otherwise you
have to ensure that each component is non-zero and not an integer
multiple of the prime for that component yourself.<span></span>
<div>
<br>
</div>
<div>The best alternative is what this version appears to use: the
crypto module. If you need something faster that doesn't have to
be safe for cryptographic purposes you'll have to look outside
of OTP.<br>
</div>
</blockquote>
<br>
If you are interested in an alternative to the random module which
does not need to be safe for cryptographic purposes, there is an
implementation of a newer algorithm done by the same authors <span
class="c">(Wichmann-Hill 2006) which has an implementation here
<a class="moz-txt-link-freetext" href="https://github.com/jj1bdx/sfmt-erlang/blob/master/src/random_wh06_int.erl">https://github.com/jj1bdx/sfmt-erlang/blob/master/src/random_wh06_int.erl</a>
. I believe this implementation is faithful to the original
algorithm and avoids precision problems by leveraging Erlang's big
integers support. However, I haven't gotten to providing tests
for the algorithm yet, because I haven't needed it yet.<br>
<br>
A simple application, is a quicker way to do a v4 UUID (i.e.,
quicker than crypto), where you are not forced to call the random
module multiple times (since random only provides 45 bits of
pseudo-randomness, but the newer 2006 algorithm provides 124 bits
of pseudo-randomness).<br>
<br>
So, if anyone is interested, that is a place to look if you need
more pseudo-randomness for non-cryptographic purposes.<br>
<br>
- Michael<br>
</span>
</body>
</html>