Pārlūkot izejas kodu

Allow to use a fixed random seed via SOURCE_DATE_EPOCH (#251)

* Allow to use a fixed random seed via SOURCE_DATE_EPOCH

this will make builds reproducible by default
for those that want it.

See https://reproducible-builds.org/ for why this matters
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.

* Replace obsolete srand FIXME with doc
Bernhard M. Wiedemann 5 gadi atpakaļ
vecāks
revīzija
38765847ba

+ 1 - 0
lib/gis/lrand48.c

@@ -72,6 +72,7 @@ long G_srand48_auto(void)
 {
     unsigned long seed;
     char *grass_random_seed = getenv("GRASS_RANDOM_SEED");
+    if(!grass_random_seed) grass_random_seed = getenv("SOURCE_DATE_EPOCH");
     if(grass_random_seed) {
         seed = strtoull(grass_random_seed, NULL, 10);
     } else {  

+ 1 - 1
lib/raster/color_rand.c

@@ -33,7 +33,7 @@ void Rast_make_random_colors(struct Colors *colors, CELL min, CELL max)
 	G_fatal_error(_("Rast_make_random_colors: min (%d) > max (%d)"),
 		      min, max);
 
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_srand48_auto();
 
     count = MAX_COLORS - DEVIATION + G_lrand48() % DEVIATION;

+ 1 - 1
raster/r.flow/main.c

@@ -318,7 +318,7 @@ static void calculate(void)
 
     ystep = region.ns_res * (double)loopstep;
 
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_srand48_auto();
 
     for (row = 0, y = (double)region.north - (region.ns_res * .5);

+ 1 - 1
raster/r.spread/main.c

@@ -335,7 +335,7 @@ int main(int argc, char *argv[])
 	exit(EXIT_FAILURE);
 
 
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_srand48_auto();
 
     display = 0;

+ 1 - 1
raster/r.surf.fractal/spec_syn.c

@@ -43,7 +43,7 @@ int specsyn(double *data[2],	/* Array holding complex data to transform. */
     double phase, rad,		/* polar coordinates of Fourier coeff.  */
      *temp[2];
 
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_math_srand_auto();	/* Reset random number generator.       */
 
     temp[0] = (double *)G_malloc(nn * nn * sizeof(double));

+ 1 - 1
raster/r.surf.gauss/gaussurf.c

@@ -32,7 +32,7 @@ int gaussurf(char *out,		/* Name of raster maps to be opened.    */
 
 	/****** INITIALISE RANDOM NUMBER GENERATOR ******/
 
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_math_srand_auto();
 
 	/****** OPEN CELL FILES AND GET CELL DETAILS ******/

+ 1 - 1
raster/r.surf.random/randsurf.c

@@ -20,7 +20,7 @@ int randsurf(char *out,		/* Name of raster maps to be opened.    */
     int row_count, col_count;
 
 	/****** INITIALISE RANDOM NUMBER GENERATOR ******/
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_math_srand_auto();
 
 	/****** OPEN CELL FILES AND GET CELL DETAILS ******/

+ 1 - 1
vector/v.extract/main.c

@@ -382,7 +382,7 @@ int main(int argc, char **argv)
 			  opt.type->answer, ucat_count);
 	
 	/* Initialise random number generator */
-	/* FIXME - allow seed to be specified for repeatability */
+	/* You can set GRASS_RANDOM_SEED for repeatability */
 	G_math_srand_auto();
 
 	/* Fill cat_array with list of valid random numbers */

+ 1 - 1
vector/v.kcv/main.c

@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
     if (np < 2)
 	G_fatal_error(_("'%s' must be > 1"), npart_opt->key);
 
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_srand48_auto();
 
     Points = Vect_new_line_struct();

+ 1 - 1
vector/v.qcount/findquads.c

@@ -29,7 +29,7 @@ COOR *find_quadrats(int n, double r, struct Cell_head window)
     if (quads == NULL)
 	G_fatal_error("cannot allocate memory for quadrats");
 
-    /* FIXME - allow seed to be specified for repeatability */
+    /* You can set GRASS_RANDOM_SEED for repeatability */
     G_srand48_auto();
 
     e_max = window.east - r;