From 35d7c78aedaf92c48bfaad1f45d666c6068413d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= Date: Tue, 16 Mar 2021 13:54:48 +0200 Subject: place: use GRand to generate random numbers Coverity CID: #1445646 --- src/core/place.c | 12 +++++++++--- 1 file 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; } -- cgit v1.2.1