summaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-06 16:50:35 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-06 16:50:35 +0100
commit8cbcc5d357fe85895dc3311f0484bbba782f026f (patch)
tree306a19d9d0ac23502d03253f53afddb9569b47ac /src/libutil
parentd83a8e52ef07190ff5be8ce1148dba1f8bb75704 (diff)
downloadrspamd-8cbcc5d357fe85895dc3311f0484bbba782f026f.tar.gz
rspamd-8cbcc5d357fe85895dc3311f0484bbba782f026f.zip
[Feature] Add utility function to return random number from 0 to 1
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.c10
-rw-r--r--src/libutil/util.h6
2 files changed, 14 insertions, 2 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 87395c568..4fc3eb613 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -2027,7 +2027,7 @@ rspamd_hash_seed (void)
}
gdouble
-rspamd_time_jitter (gdouble in, gdouble jitter)
+rspamd_random_double (void)
{
guint64 rnd_int;
double res;
@@ -2037,11 +2037,17 @@ rspamd_time_jitter (gdouble in, gdouble jitter)
res = rnd_int;
res *= transform_bias;
+ return res;
+}
+
+gdouble
+rspamd_time_jitter (gdouble in, gdouble jitter)
+{
if (jitter == 0) {
jitter = in;
}
- return in + jitter * res;
+ return in + jitter * rspamd_random_double ();
}
gboolean
diff --git a/src/libutil/util.h b/src/libutil/util.h
index ec8150fae..48e91cb4f 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -410,6 +410,12 @@ guint64 rspamd_hash_seed (void);
gdouble rspamd_time_jitter (gdouble in, gdouble jitter);
/**
+ * Return random double in range [0..1)
+ * @return
+ */
+gdouble rspamd_random_double (void);
+
+/**
* Constant time version of memcmp
*/
gboolean rspamd_constant_memcmp (const guchar *a, const guchar *b, gsize len);