From 43cc30bca8c0eec5fdf5e3ac3a712ad84497db51 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 6 Mar 2021 20:12:07 +0000 Subject: Use Mersenee Twister instead of libc rand for random numbers git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4033 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/pnmremap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'editor/pnmremap.c') diff --git a/editor/pnmremap.c b/editor/pnmremap.c index 0c0096ba..e5b59d04 100644 --- a/editor/pnmremap.c +++ b/editor/pnmremap.c @@ -28,6 +28,7 @@ #include "pm_c_util.h" #include "mallocvar.h" #include "nstring.h" +#include "rand.h" #include "shhopt.h" #include "pam.h" #include "ppm.h" @@ -399,20 +400,21 @@ randomizeError(long ** const err, Set a random error in the range [-1 .. 1] (normalized via FS_SCALE) in the error array err[][]. -----------------------------------------------------------------------------*/ - unsigned int const seed = (random.init == RANDOM_WITHSEED) ? - random.seed : pm_randseed(); - unsigned int col; + struct pm_randSt randSt; assert(random.init != RANDOM_NONE); - srand(seed); + pm_randinit(&randSt); + pm_srand2(&randSt, random.init == RANDOM_WITHSEED, random.seed); for (col = 0; col < width; ++col) { unsigned int plane; for (plane = 0; plane < depth; ++plane) - err[plane][col] = rand() % (FS_SCALE * 2) - FS_SCALE; + err[plane][col] = pm_rand(&randSt) % (FS_SCALE * 2) - FS_SCALE; } + + pm_randterm(&randSt); } -- cgit 1.4.1