summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberts Muktupāvels <alberts.muktupavels@gmail.com>2021-03-16 13:54:48 +0200
committerAlberts Muktupāvels <alberts.muktupavels@gmail.com>2021-03-16 13:54:48 +0200
commit35d7c78aedaf92c48bfaad1f45d666c6068413d2 (patch)
tree5fb977976e822045cf43d7dd0d1b8a87cad14466
parent103d6b281227959ba6bf041e6df47f7282d8e9b4 (diff)
downloadmetacity-35d7c78aedaf92c48bfaad1f45d666c6068413d2.tar.gz
place: use GRand to generate random numbers
Coverity CID: #1445646
-rw-r--r--src/core/place.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/core/place.c b/src/core/place.c
index 70e80b7f..9ed8ecce 100644
--- a/src/core/place.c
+++ b/src/core/place.c
@@ -702,6 +702,10 @@ find_preferred_position (MetaWindow *window,
*/
if ((rect.width <= work_area.width) && (rect.height <= work_area.height))
{
+ GRand *rand;
+
+ rand = g_rand_new ();
+
switch (placement_mode_pref)
{
case META_PLACEMENT_MODE_CENTER:
@@ -717,9 +721,9 @@ find_preferred_position (MetaWindow *window,
case META_PLACEMENT_MODE_RANDOM:
*new_x = (int) ((float) (work_area.width - rect.width) *
- ((float) rand() / (float) RAND_MAX));
+ (float) g_rand_double (rand));
*new_y = (int) ((float) (work_area.height - rect.height) *
- ((float) rand() / (float) RAND_MAX));
+ (float) g_rand_double (rand));
*new_x += work_area.x;
*new_y += work_area.y;
break;
@@ -736,8 +740,8 @@ find_preferred_position (MetaWindow *window,
default:
g_warning ("Unknown window-placement option chosen.");
+ g_rand_free (rand);
return FALSE;
- break;
}
if (borders)
@@ -746,6 +750,8 @@ find_preferred_position (MetaWindow *window,
*new_y += borders->visible.top;
}
+ g_rand_free (rand);
+
return TRUE;
}