[FFmpeg-devel] [PATCHv3 2/3] lavu/rand: add Ziggurat algorithm for normal random number generation

Michael Niedermayer michael at niedermayer.cc
Tue Mar 15 23:54:54 CET 2016


On Tue, Mar 15, 2016 at 12:47:00AM -0400, Ganesh Ajjanagadde wrote:
[...]
> +static inline double ziggurat(AVRAND64 *rng)
> +{
> +    while (1) {
> +        int64_t rabs;
> +        double x;
> +        uint8_t idx;
> +        uint64_t r = av_rand64_get(rng) & 0x000fffffffffffff;
> +        rabs = (int64_t) (r >> 1);
> +        idx = rabs & 0xff;
> +        x = ((r & 1) ? -rabs : rabs) * wi[idx];

to get good quality numbers from most PRNGs the MSBs are better than
the LSBs
this is true for LCGs, LFGs, xorshift128+ and others

also the commonly used PRNG tests are biased toward testing the
MSBs when they test the numbers as scalars



[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160315/e0c3d1d1/attachment.sig>


More information about the ffmpeg-devel mailing list