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

Kenji Rikitake <>
Wed Dec 1 01:09:29 CET 2010

```Robert and all:

The reason why I picked up Wichmann-Hill's 2006 algorithm was exactly
what you wrote below.  Here's some observations:

* generated random number range: same (0.0 =< Result < 1.0)

* performance: ~9% slower when running in an infinite loop
(old: ~67000, new ~60000 samples/sec
on Erlang/OTP R14B FreeBSD/i386 Core2Duo 1.8GHz with no HiPE)

* seed elements: old 3, new 4, as Robert pointed out.

I don't have an idea about generating two elements from one.

Also I think the seeding function should be

seed(A1, A2, A3, A4) ->
put(random_wh06_seed,
{abs(A1 - 1) rem 2147483578 + 1,
abs(A2 - 1) rem 2147483542 + 1,
abs(A3 - 1) rem 2147483422 + 1,
abs(A4 - 1) rem 2147483122 + 1}).

so that {0, 0, 0, 0} -> {1, 1, 1, 1}
while {1, 2, 3, 4} -> {1, 2, 3, 4}.
(The zero values must be avoided)

* seed values: old unsigned 16bit, new unsigned 32bit
(This will not cause any serious issue)

* Licensing issues: the algorithm is openly published in an academic
paper, though the NPL (the copyright holder) code is not in the open
license.  I think changing the default seeding (at seed/0) values from
the NPL code (already done) will be sufficient to avoid the licensing
issues.

Any other points?

Kenji Rikitake

In the message <>
dated Tue, Nov 30, 2010 at 10:50:11PM +0000,
Robert Virding <> writes:
> What would be nice is if we could just drop the new algorithm into the old module so we avoid having to have 2 random modules. As I see it the main problem is that the old random has 3 seeds while the new has 4, which makes the seed functions incompatible. Couldn't you just have one seed be two?
>
> It would mean that the "new" random would return better values, but they would be different from what the "old" random returned. I don't see this as a problem but others might.
>
> Robert

> > > > The 2006 Wichmann-Hill RNG for Erlang moved to
> > > > https://gist.github.com/713144
> > > > under the name of
> > > > random_wh06.erl
```