[metacity] place: use GRand to generate random numbers
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] place: use GRand to generate random numbers
- Date: Tue, 16 Mar 2021 13:34:18 +0000 (UTC)
commit 35d7c78aedaf92c48bfaad1f45d666c6068413d2
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Mar 16 13:54:48 2021 +0200
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 70e80b7f4..9ed8ecce7 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]