1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-04-03 14:23:07 +02:00

GRand: avoid overflow

Otherwise, g_random_double_range (-G_MAXDOUBLE, G_MAXDOUBLE)
doesn't work as expected.

https://bugzilla.gnome.org/show_bug.cgi?id=502560
This commit is contained in:
Matthias Clasen 2011-06-03 23:37:23 -04:00
parent deed4dd36b
commit 77be95cdce

@ -586,7 +586,11 @@ g_rand_double (GRand* rand)
gdouble gdouble
g_rand_double_range (GRand* rand, gdouble begin, gdouble end) g_rand_double_range (GRand* rand, gdouble begin, gdouble end)
{ {
return g_rand_double (rand) * (end - begin) + begin; gdouble r;
r = g_rand_double (rand);
return r * end - (r - 1) * begin;
} }
/** /**