aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/util.c
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/util.c
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/util.c')
-rw-r--r--src/libutil/util.c10
1 files changed, 8 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