[erlang-questions] Implementation of a 2006 version of Wichmann-Hull random number generator for Erlang/OTP

Cristian Greco cristian@REDACTED
Tue Nov 23 15:58:47 CET 2010

On Tue, 23 Nov 2010 21:59:19 +0900
Kenji Rikitake <kenji.rikitake@REDACTED> wrote:

> Greco: Yes - I remembered your code pieces and bug reports.
> I should add that giving zero to any of the seed tuple elements will
> render the random number generator useless because the zeros will stay
> forever, and that this should be checked at least in the (re)seeding
> functions.  (This is a known limitation of the algorithm based on
> multiplicative congluency generators.)

Sure, you're right. This happens for seeds which are multiples of the
modules used by the generator:

1> S = [ {N*30269,N*30307,N*30323} || N <- lists:seq(0,4) ].  
2> lists:map(fun({A,B,C}) -> random:seed(A,B,C), io:format("~p~n",
[[random:uniform() || _ <- lists:seq(1,10)]]) end, S).   

The actual prng in Erlang is intrinsecally limited in many ways.
IMHO you should rework your MT nif implementation and submit it as a
patch for stdlib. A bonus would be the code to provide access to
OS-dependant randomness sources (e.g. /dev/urandom in *nix, CryptoApi
in windows), in order to automatically initialize the generator with a
"non-hardcoded" seed.

Cristian Greco
GPG key ID: 0xCF4D32E4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20101123/e20e4fef/attachment.bin>

More information about the erlang-questions mailing list