summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bb65913)
raw | patch | inline | side by side (parent: bb65913)
author | Florian Forster <octo@collectd.org> | |
Sun, 24 Mar 2013 13:21:27 +0000 (14:21 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 24 Mar 2013 13:21:27 +0000 (14:21 +0100) |
src/rrdtool.c | patch | blob | history |
diff --git a/src/rrdtool.c b/src/rrdtool.c
index e7c48c0e7ee7baf1b2fbed4a7dc668e50acfcb70..2c80762ecb905454f843620fd86cf3cd449ba8f7 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
/**
* collectd - src/rrdtool.c
- * Copyright (C) 2006-2008 Florian octo Forster
+ * Copyright (C) 2006-2013 Florian octo Forster
* Copyright (C) 2008-2008 Sebastian Harl
* Copyright (C) 2009 Mariusz Gronczewski
*
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
* Sebastian Harl <sh at tokkee.org>
* Mariusz Gronczewski <xani666 at gmail.com>
**/
#include "plugin.h"
#include "common.h"
#include "utils_avltree.h"
+#include "utils_random.h"
#include "utils_rrdcreate.h"
#include <rrd.h>
static int64_t rrd_get_random_variation (void)
{
- double dbl_timeout;
- cdtime_t ctm_timeout;
- double rand_fact;
- _Bool negative;
- int64_t ret;
+ long min;
+ long max;
if (random_timeout <= 0)
return (0);
random_timeout = cache_timeout;
}
- /* This seems a bit complicated, but "random_timeout" is likely larger than
- * RAND_MAX, so we can't simply use modulo here. */
- dbl_timeout = CDTIME_T_TO_DOUBLE (random_timeout);
- rand_fact = ((double) random ())
- / ((double) RAND_MAX);
- negative = (_Bool) (random () % 2);
+ max = (long) (random_timeout / 2);
+ min = max - ((long) random_timeout);
- ctm_timeout = DOUBLE_TO_CDTIME_T (dbl_timeout * rand_fact);
-
- ret = (int64_t) ctm_timeout;
- if (negative)
- ret *= -1;
-
- return (ret);
+ return ((int64_t) cdrand_range (min, max));
} /* int64_t rrd_get_random_variation */
static int rrd_cache_insert (const char *filename,