瀏覽代碼

If GRASS_RANDOM_SEED is set, use it to seed the random generator when
G_srand48_auto is called. This helps makeing the build reproducible
(html/random.png)
Based on 04-srand48_auto-from-SOURCE_DATE_EPOCH.patch, see https://trac.osgeo.org/grass/ticket/3042


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@69217 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 8 年之前
父節點
當前提交
a099817b0d
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      lib/gis/lrand48.c

+ 7 - 1
lib/gis/lrand48.c

@@ -70,7 +70,12 @@ void G_srand48(long seedval)
 
 
 long G_srand48_auto(void)
 long G_srand48_auto(void)
 {
 {
-    unsigned long seed = (unsigned long) getpid();
+    unsigned long seed;
+    char *grass_random_seed = getenv("GRASS_RANDOM_SEED");
+    if(grass_random_seed) {
+        seed = strtoull(grass_random_seed, NULL, 10);
+    } else {  
+        seed = (unsigned long) getpid();
 
 
 #ifdef HAVE_GETTIMEOFDAY
 #ifdef HAVE_GETTIMEOFDAY
     {
     {
@@ -86,6 +91,7 @@ long G_srand48_auto(void)
 	seed += (unsigned long) t;
 	seed += (unsigned long) t;
     }
     }
 #endif
 #endif
+    }
 
 
     G_srand48((long) seed);
     G_srand48((long) seed);
     return (long) seed;
     return (long) seed;