--- netpbm-svn-3697.old/editor/pnmremap.c +++ netpbm-svn-3697/editor/pnmremap.c @@ -403,10 +403,54 @@ random.seed : pm_randseed(); unsigned int col; + int c; + char *cp; assert(random.init != RANDOM_NONE); - srand(seed); +/* ------------------------------------------------------------ */ + +/* This version of "pnmremap.c" supports an environment vari- */ +/* able named PNMREMAPRAND. If the variable is defined, and its */ +/* value starts with "f" or "F" [short for FALSE] or "n" or "N" */ +/* [short for "NO"], "pnmremap.c" uses a fixed random-number */ +/* seed. */ + +/* The PNMREMAPRAND feature was added for the benefit of a new */ +/* program named "ppmquantnr". The new program is equivalent to */ +/* the existing "ppmquant" program, with one difference: "ppm- */ +/* quantnr" sets PNMREMAPRAND to NO. The change means that the */ +/* user will get consistent results if he or she executes the */ +/* same "ppmquantnr" command repeatedly for identical input */ +/* files at different times. This is a useful feature for some */ +/* applications. */ + +/* As of 2019, "pnmremap.c" seems to include a similar feature */ +/* of its own. The PNMREMAPRAND feature will be retained, re- */ +/* gardless, for the sake of backwards compatibility. */ + + c = 0; + + if ((cp = getenv ("PNMREMAPRAND")) != NULL) + { + c = *cp; + if ((c >= 'a') && (c <= 'z')) c += 'A' - 'a'; + } + /* Produce consistent results? */ + if ((c == 'F') || (c == 'N')) + { /* Yes */ + srand ((int) 0x3DBA656FL); + } + else + { /* No - Default behavior */ +#ifdef NOTDEF + srand ((int) (time (0) ^ getpid())); +#else + srand (seed); +#endif + } + +/* ------------------------------------------------------------ */ for (col = 0; col < width; ++col) { unsigned int plane;