[GRASS-SVN] r73235 - in grass/branches/releasebranch_7_6/raster: r.random.cells r.random.surface
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 3 13:04:40 PDT 2018
Author: mmetz
Date: 2018-09-03 13:04:40 -0700 (Mon, 03 Sep 2018)
New Revision: 73235
Modified:
grass/branches/releasebranch_7_6/raster/r.random.cells/init.c
grass/branches/releasebranch_7_6/raster/r.random.cells/main.c
grass/branches/releasebranch_7_6/raster/r.random.cells/random.c
grass/branches/releasebranch_7_6/raster/r.random.cells/ransurf.h
grass/branches/releasebranch_7_6/raster/r.random.surface/init.c
grass/branches/releasebranch_7_6/raster/r.random.surface/main.c
grass/branches/releasebranch_7_6/raster/r.random.surface/random.c
grass/branches/releasebranch_7_6/raster/r.random.surface/ransurf.h
Log:
r.random.cells, r.random.surface: use G_drand48(), fixes #2496 (backport trunk r73234)
Modified: grass/branches/releasebranch_7_6/raster/r.random.cells/init.c
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.cells/init.c 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.cells/init.c 2018-09-03 20:04:40 UTC (rev 73235)
@@ -79,19 +79,16 @@
G_debug(3, "(MaxDist):%.12lf", MaxDist);
MaxDistSq = MaxDist * MaxDist;
if (!SeedStuff->answer) {
- Seed = (int)getpid();
+ Seed = -1;
}
else {
sscanf(SeedStuff->answer, "%d", &(Seed));
}
- if (Seed > SEED_MAX) {
- Seed = Seed % SEED_MAX;
- }
- else if (Seed < SEED_MIN) {
- while (Seed < SEED_MIN)
- Seed += SEED_MAX - SEED_MIN;
- }
+ if (Seed < 0)
+ G_srand48_auto();
+ else
+ G_srand48(Seed);
G_message(_("Generating raster map <%s>..."),
Output->answer);
Modified: grass/branches/releasebranch_7_6/raster/r.random.cells/main.c
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.cells/main.c 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.cells/main.c 2018-09-03 20:04:40 UTC (rev 73235)
@@ -74,7 +74,7 @@
SeedStuff->type = TYPE_INTEGER;
SeedStuff->required = NO;
SeedStuff->description =
- _("Random seed (SEED_MIN >= value >= SEED_MAX) (default [random])");
+ _("Random seed, default [random]");
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass/branches/releasebranch_7_6/raster/r.random.cells/random.c
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.cells/random.c 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.cells/random.c 2018-09-03 20:04:40 UTC (rev 73235)
@@ -4,53 +4,10 @@
#include "ransurf.h"
-#define M1 259200
-#define IA1 7141
-#define IC1 54773
-#define RM1 (1.0/M1)
-#define M2 134456
-#define IA2 8121
-#define IC2 28411
-#define RM2 (1.0/M2)
-#define M3 243000
-#define IA3 4561
-#define IC3 51349
-
/* ran1() returns a double with a value between 0.0 and 1.0 */
double ran1(void)
{
- static long ix1, ix2, ix3;
- static double r[98];
- double temp;
- static int iff = 0;
- int j;
-
G_debug(2, "ran1()");
- if (Seed < 0 || iff == 0) {
- iff = 1;
- ix1 = (IC1 - Seed) % M1;
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix2 = ix1 % M2;
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix3 = ix1 % M3;
- for (j = 1; j <= 97; j++) {
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix2 = (IA2 * ix2 + IC2) % M2;
- r[j] = (ix1 + ix2 * RM2) * RM1;
- }
- Seed = 1;
- }
-
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix2 = (IA2 * ix2 + IC2) % M2;
- ix3 = (IA3 * ix3 + IC3) % M3;
- j = 1 + ((97 * ix3) / M3);
- if (j > 97 || j < 1)
- G_fatal_error(_("RAN1: j == %d shouldn't happen"), j);
-
- temp = r[j];
- r[j] = (ix1 + ix2 * RM2) * RM1;
-
- return temp;
+ return G_drand48();
}
Modified: grass/branches/releasebranch_7_6/raster/r.random.cells/ransurf.h
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.cells/ransurf.h 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.cells/ransurf.h 2018-09-03 20:04:40 UTC (rev 73235)
@@ -7,8 +7,6 @@
#define ODD(a) ((a) & 1)
-#define SEED_MAX 54772
-#define SEED_MIN 0
#define PI M_PI
#define CELLSORTER struct cell_sorter_
Modified: grass/branches/releasebranch_7_6/raster/r.random.surface/init.c
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.surface/init.c 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.surface/init.c 2018-09-03 20:04:40 UTC (rev 73235)
@@ -94,33 +94,15 @@
Theory = 0;
NumSeeds = 0;
Seeds = (int *)G_malloc(NumMaps * sizeof(int));
+ Seed = -1;
if (!SeedStuff->answers) {
for (i = 0; i < NumMaps; i++) {
- Seeds[i] = SEED_MIN - 1;
- Seed = (int)getpid();
+ Seeds[i] = -1;
}
}
else {
for (i = 0; (Number = SeedStuff->answers[i]) && i < NumMaps; i++) {
sscanf(Number, "%d", &(Seeds[i]));
- if (Seeds[i] > SEED_MAX) {
-
- sprintf(msg, _("Seed (%d) larger than maximum (%d)"),
- Seeds[i], SEED_MAX);
- Seeds[i] = Seeds[i] % SEED_MAX;
- sprintf(msg2, _(" seed is set to %d"), Seeds[i]);
- strcat(msg, msg2);
- G_warning("%s", msg);
- }
- else if (Seeds[i] < SEED_MIN) {
- sprintf(msg, _("Seed (%d) smaller than minimum (%d)"),
- Seeds[i], SEED_MIN);
- while (Seeds[i] < SEED_MIN)
- Seeds[i] += SEED_MAX - SEED_MIN;
- sprintf(msg2, _(" seed is set to %d"), Seeds[i]);
- strcat(msg, msg2);
- G_warning("%s", msg);
- }
} /* /for */
} /* /else */
Modified: grass/branches/releasebranch_7_6/raster/r.random.surface/main.c
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.surface/main.c 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.surface/main.c 2018-09-03 20:04:40 UTC (rev 73235)
@@ -99,7 +99,7 @@
SeedStuff->type = TYPE_INTEGER;
SeedStuff->required = NO;
SeedStuff->description =
- _("Random seed (SEED_MIN >= value >= SEED_MAX), default [random]");
+ _("Random seed, default [random]");
range_high_stuff = G_define_option();
range_high_stuff->key = "high";
@@ -127,8 +127,10 @@
G_message(_("Generating raster map <%s>..."), OutNames[DoMap]);
- if (Seeds[DoMap] == SEED_MIN - 1)
- Seeds[DoMap] = (int)(ran1() * SEED_MAX);
+ if (Seeds[DoMap] < 0)
+ G_srand48_auto();
+ else
+ G_srand48(Seeds[DoMap]);
MapSeed = Seed = Seeds[DoMap];
ZeroMapCells();
Modified: grass/branches/releasebranch_7_6/raster/r.random.surface/random.c
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.surface/random.c 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.surface/random.c 2018-09-03 20:04:40 UTC (rev 73235)
@@ -2,54 +2,10 @@
#include <grass/gis.h>
#include "ransurf.h"
-#define M1 259200
-#define IA1 7141
-#define IC1 54773
-#define RM1 (1.0/M1)
-#define M2 134456
-#define IA2 8121
-#define IC2 28411
-#define RM2 (1.0/M2)
-#define M3 243000
-#define IA3 4561
-#define IC3 51349
-
/* ran1() returns a double with a value between 0.0 and 1.0 */
double ran1(void)
{
- static long ix1, ix2, ix3;
- static double r[98];
- double temp;
- static int iff = 0;
- int j;
-
G_debug(2, "ran1()");
- if (Seed < 0 || iff == 0) {
- iff = 1;
- ix1 = (IC1 - Seed) % M1;
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix2 = ix1 % M2;
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix3 = ix1 % M3;
-
- for (j = 1; j <= 97; j++) {
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix2 = (IA2 * ix2 + IC2) % M2;
- r[j] = (ix1 + ix2 * RM2) * RM1;
- }
- Seed = 1;
- }
-
- ix1 = (IA1 * ix1 + IC1) % M1;
- ix2 = (IA2 * ix2 + IC2) % M2;
- ix3 = (IA3 * ix3 + IC3) % M3;
- j = 1 + ((97 * ix3) / M3);
- if (j > 97 || j < 1)
- G_fatal_error("RAN1: j==%d shouldn't happen", j);
-
- temp = r[j];
- r[j] = (ix1 + ix2 * RM2) * RM1;
-
- return temp;
+ return G_drand48();
}
Modified: grass/branches/releasebranch_7_6/raster/r.random.surface/ransurf.h
===================================================================
--- grass/branches/releasebranch_7_6/raster/r.random.surface/ransurf.h 2018-09-03 20:03:54 UTC (rev 73234)
+++ grass/branches/releasebranch_7_6/raster/r.random.surface/ransurf.h 2018-09-03 20:04:40 UTC (rev 73235)
@@ -8,8 +8,6 @@
#define ODD(a) ((a) & 1)
-#define SEED_MAX 54772
-#define SEED_MIN 0
#define MAX_INTERVAL 10
#define MIN_INTERVAL -10
/* DELTA_T is the inverse of the number of subdivisions within the */
More information about the grass-commit
mailing list