[GRASS-SVN] r72886 - grass/trunk/raster/r.random
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jun 23 01:55:37 PDT 2018
Author: mmetz
Date: 2018-06-23 01:55:37 -0700 (Sat, 23 Jun 2018)
New Revision: 72886
Removed:
grass/trunk/raster/r.random/creat_rand.c
Modified:
grass/trunk/raster/r.random/local_proto.h
grass/trunk/raster/r.random/main.c
grass/trunk/raster/r.random/random.c
Log:
r.random: add seed option to set the seed of the RNG (fixes #3594)
Deleted: grass/trunk/raster/r.random/creat_rand.c
===================================================================
--- grass/trunk/raster/r.random/creat_rand.c 2018-06-22 21:39:11 UTC (rev 72885)
+++ grass/trunk/raster/r.random/creat_rand.c 2018-06-23 08:55:37 UTC (rev 72886)
@@ -1,14 +0,0 @@
-#include <grass/gis.h>
-
-
-long make_rand(void)
-{
- return G_lrand48();
-}
-
-void init_rand(void)
-{
- /* FIXME - allow seed to be specified for repeatability */
- G_srand48_auto();
-}
-
Modified: grass/trunk/raster/r.random/local_proto.h
===================================================================
--- grass/trunk/raster/r.random/local_proto.h 2018-06-22 21:39:11 UTC (rev 72885)
+++ grass/trunk/raster/r.random/local_proto.h 2018-06-23 08:55:37 UTC (rev 72886)
@@ -44,12 +44,6 @@
/* count.c */
void get_stats(struct rr_state *);
-/* creat_rand.c */
-long make_rand(void);
-void init_rand(void);
-long make_rand(void);
-void init_rand(void);
-
/* random.c */
int execute_random(struct rr_state *);
Modified: grass/trunk/raster/r.random/main.c
===================================================================
--- grass/trunk/raster/r.random/main.c 2018-06-22 21:39:11 UTC (rev 72885)
+++ grass/trunk/raster/r.random/main.c 2018-06-23 08:55:37 UTC (rev 72886)
@@ -34,11 +34,12 @@
gcell_count targets;
gcell_count count;
struct rr_state myState;
+ long seed_value;
struct GModule *module;
struct
{
- struct Option *input, *cover, *raster, *sites, *npoints;
+ struct Option *input, *cover, *raster, *sites, *npoints, *seed;
} parm;
struct
{
@@ -81,6 +82,12 @@
parm.sites->required = NO;
parm.sites->key = "vector";
+ parm.seed = G_define_option();
+ parm.seed->key = "seed";
+ parm.seed->type = TYPE_INTEGER;
+ parm.seed->required = NO;
+ parm.seed->description = _("Seed for rand() function");
+
flag.zero = G_define_flag();
flag.zero->key = 'z';
flag.zero->description = _("Generate points also for NULL category");
@@ -194,6 +201,16 @@
myState.nRand = targets;
}
+ if (parm.seed->answer) {
+ seed_value = atol(parm.seed->answer);
+ G_srand48(seed_value);
+ G_debug(3, "Read random seed from seed=: %ld", seed_value);
+ }
+ else {
+ seed_value = G_srand48_auto();
+ G_debug(3, "Generated random seed (-s): %ld", seed_value);
+ }
+
execute_random(&myState);
if (myState.outraster)
Modified: grass/trunk/raster/r.random/random.c
===================================================================
--- grass/trunk/raster/r.random/random.c 2018-06-22 21:39:11 UTC (rev 72885)
+++ grass/trunk/raster/r.random/random.c 2018-06-23 08:55:37 UTC (rev 72886)
@@ -116,7 +116,6 @@
G_percent(0, theState->nRand, 2);
- init_rand();
nc = (theState->use_nulls) ? theState->nCells :
theState->nCells - theState->nNulls;
nt = theState->nRand; /* Number of points to generate */
@@ -141,7 +140,7 @@
do_check = 0;
}
- if (do_check && make_rand() % nc < nt) {
+ if (do_check && G_lrand48() % nc < nt) {
nt--;
if (is_null_value(theState->buf, col))
cpvalue(&theState->nulls, 0, &theState->buf, col);
More information about the grass-commit
mailing list