[GRASS-SVN] r53234 - grass/trunk/vector/v.kcv
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 19 06:09:05 PDT 2012
Author: glynn
Date: 2012-09-19 06:09:05 -0700 (Wed, 19 Sep 2012)
New Revision: 53234
Removed:
grass/trunk/vector/v.kcv/utils.c
Modified:
grass/trunk/vector/v.kcv/kcv.h
grass/trunk/vector/v.kcv/main.c
Log:
Fix RNG handling
Modified: grass/trunk/vector/v.kcv/kcv.h
===================================================================
--- grass/trunk/vector/v.kcv/kcv.h 2012-09-19 12:59:23 UTC (rev 53233)
+++ grass/trunk/vector/v.kcv/kcv.h 2012-09-19 13:09:05 UTC (rev 53234)
@@ -8,6 +8,3 @@
/* histo.c */
int make_histo(int **, int, int);
-
-/* utils.c */
-double myrand(void);
Modified: grass/trunk/vector/v.kcv/main.c
===================================================================
--- grass/trunk/vector/v.kcv/main.c 2012-09-19 12:59:23 UTC (rev 53233)
+++ grass/trunk/vector/v.kcv/main.c 2012-09-19 13:09:05 UTC (rev 53234)
@@ -25,28 +25,19 @@
#include <grass/glocale.h>
#include "kcv.h"
-#ifndef RAND_MAX
-#define RAND_MAX (pow(2.0,31.0)-1)
-#endif
-#if defined(__CYGWIN__) || defined(__APPLE__) || defined(__MINGW32__)
-double drand48()
+static double myrand(void)
{
- return (rand() / 32767.0);
+ return rand() / (1.0 * RAND_MAX);
}
-#define srand48(sv) (srand((unsigned)(sv)))
-#else
-double drand48();
-void srand48();
-#endif
-
struct Cell_head window;
int main(int argc, char *argv[])
{
int line, nlines, nlinks;
- double east, north, (*rng) (), max, myrand();
- int i, j, nsites, np, *p, dcmp();
+ double (*rng)(void);
+ double east, north;
+ int i, j, nsites, np, *p;
int *pnt_part;
struct Map_info In, Out;
static struct line_pnts *Points;
@@ -94,7 +85,11 @@
drand48_flag = G_define_flag();
drand48_flag->key = 'd';
+#ifdef HAVE_DRAND48
drand48_flag->description = _("Use drand48()");
+#else
+ drand48_flag->description = _("Use drand48() (ignored)");
+#endif
G_gisinit(argv[0]);
@@ -103,14 +98,15 @@
np = atoi(npart_opt->answer);
+#ifdef HAVE_DRAND48
if (drand48_flag->answer) {
rng = drand48;
- max = 1.0;
srand48((long)getpid());
}
- else {
+ else
+#endif
+ {
rng = myrand;
- max = RAND_MAX;
srand(getpid());
}
@@ -204,8 +200,8 @@
int nearest = 0;
double dist;
- east = rng() / max * (box.E - box.W) + box.W;
- north = rng() / max * (box.N - box.S) + box.S;
+ east = rng() * (box.E - box.W) + box.W;
+ north = rng() * (box.N - box.S) + box.S;
G_debug(3, "east = %f north = %f", east, north);
Deleted: grass/trunk/vector/v.kcv/utils.c
===================================================================
--- grass/trunk/vector/v.kcv/utils.c 2012-09-19 12:59:23 UTC (rev 53233)
+++ grass/trunk/vector/v.kcv/utils.c 2012-09-19 13:09:05 UTC (rev 53234)
@@ -1,17 +0,0 @@
-/*
- * Copyright (C) 1993-1994. James Darrell McCauley. (darrell at mccauley-usa.com)
- * http://mccauley-usa.com/
- *
- * This program is free software under the GPL (>=v2)
- * Read the file GPL.TXT coming with GRASS for details.
- */
-
-#include <grass/gis.h>
-#include "kcv.h"
-
-double myrand(void)
-{
- int rand();
-
- return (double)rand();
-}
More information about the grass-commit
mailing list