diff --git a/ChangeLog b/ChangeLog index 0508a729..f1da215a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ - add support for another quantiser [DarthSim] - jpeg2000 load left-justifies bitdepth - add "password" option to pdfload +- improve the pixel rng 26/11/21 started 8.12.3 - better arg checking for hist_find_ndim [travisbell] diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index 6e0fe6c0..bce0d9a4 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1918,18 +1918,28 @@ vips_realpath( const char *path ) /* A very simple random number generator. See: * http://isthe.com/chongo/tech/comp/fnv/#FNV-source */ +guint32 +vips__random_add( guint32 hash, int value ) +{ +#define FNV_ADD( HASH, VALUE8 ) (((HASH) ^ (VALUE8)) * 16777619u) + + hash = FNV_ADD( hash, value & 0xff ); + hash = FNV_ADD( hash, (value >> 8) & 0xff ); + hash = FNV_ADD( hash, (value >> 16) & 0xff ); + hash = FNV_ADD( hash, (value >> 24) & 0xff ); + + return( hash ); +} + guint32 vips__random( guint32 seed ) { - return( 1103515245u * seed + 12345 ); -} + guint32 hash; -guint32 -vips__random_add( guint32 seed, int value ) -{ - seed = ((2166136261u ^ seed) * 16777619u) ^ value; + hash = 2166136261u; + hash = vips__random_add( hash, seed ); - return( vips__random( seed ) ); + return( hash ); } static void *