summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 41bff0a)
raw | patch | inline | side by side (parent: 41bff0a)
author | Florian Forster <octo@collectd.org> | |
Mon, 5 Dec 2016 10:49:34 +0000 (11:49 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 5 Dec 2016 10:49:34 +0000 (11:49 +0100) |
src/daemon/utils_random.c | patch | blob | history | |
src/daemon/utils_random.h | patch | blob | history |
index 34cf5b80669b861281b654d9901695da4fcebc58..d490986dab2d746a07780845d78874de55b65941 100644 (file)
have_seed = 1;
}
-double cdrand_d(void) {
+double cdrand_d() {
double r;
pthread_mutex_lock(&lock);
return (r);
}
+uint32_t cdrand_u() {
+ long r;
+
+ pthread_mutex_lock(&lock);
+ cdrand_seed();
+ r = jrand48(seed);
+ pthread_mutex_unlock(&lock);
+
+ return (uint32_t)r;
+}
+
long cdrand_range(long min, long max) {
long range;
long r;
index d56bcf6a614ef443f0b5972976821c791557e0ed..e25ae9b67829c4579406e7d96e912f1bcdeab4af 100644 (file)
*
* This function is thread- and reentrant-safe.
*/
-double cdrand_d(void);
+double cdrand_d();
+
+/**
+ * cdrand_u returns a random uint32_t value uniformly distributed in the range
+ * [0-2^32).
+ *
+ * This function is thread- and reentrant-safe.
+ */
+uint32_t cdrand_u();
/**
* Returns a random long between min and max, inclusively.