Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Replace the extremely poor drand48 with a proper one #428

Open
rurban opened this issue Nov 28, 2020 · 0 comments
Open

Replace the extremely poor drand48 with a proper one #428

rurban opened this issue Nov 28, 2020 · 0 comments
Assignees

Comments

@rurban
Copy link
Member

rurban commented Nov 28, 2020

Note that the perl5 design choices for drand48() are extremely poor. (but not entirely unexpected from p5p).

1st: Taking the primitive freebsd rand48() they use ldexp(.., -48)
to expand the 48 bits to a double, not the much faster bitmasking.
ldexp uses 5 branches and 1-2 multiplications. This is ~2x slower than needed.
The FreeBSD original is sane here, but even gsl is doing the same. Wonder who was first.

2nd: Masking to 48 bits not 53 makes creating uniform double values much harder.
Normally you would create 64-bit numbers as with every other rng. Then
you have proper int ranges as well as double.

Use a good one instead, which works on 32bit and 64bit systems,
producing full range ints and doubles, and much faster. e.g wyrand.
See https://rurban.github.io/dieharder/QUALITY.html (look for drand48 at the bottom).

And while we are here, seperate pp_rand into int and double methods.
It makes not much sense to produce costly doubles, when only int values are requested.

Already filed at #10, then I thought PCG or xoroshiro128+ would be best (before actually testing them)

@rurban rurban self-assigned this Nov 28, 2020
@rurban rurban changed the title Replace the extermely poor drand48 with a proper one Replace the extremely poor drand48 with a proper one Nov 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant