[metacity] testboxes: use GRand to generate random numbers
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] testboxes: use GRand to generate random numbers
- Date: Tue, 16 Mar 2021 13:34:18 +0000 (UTC)
commit 811b671e52d07b8737ae8008bb2bf18ebdca6d15
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Mar 16 14:04:16 2021 +0200
testboxes: use GRand to generate random numbers
Coverity CID: #1418268
src/core/testboxes.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/src/core/testboxes.c b/src/core/testboxes.c
index f4cd3a507..e59db39b3 100644
--- a/src/core/testboxes.c
+++ b/src/core/testboxes.c
@@ -28,19 +28,15 @@
#define NUM_RANDOM_RUNS 10000
-static void
-init_random_ness (void)
-{
- srand(time(NULL));
-}
+static GRand *grand = NULL;
static void
get_random_rect (MetaRectangle *rect)
{
- rect->x = rand () % 1600;
- rect->y = rand () % 1200;
- rect->width = rand () % 1600 + 1;
- rect->height = rand () % 1200 + 1;
+ rect->x = g_rand_int (grand) % 1600;
+ rect->y = g_rand_int (grand) % 1200;
+ rect->width = g_rand_int (grand) % 1600 + 1;
+ rect->height = g_rand_int (grand) % 1200 + 1;
}
static MetaRectangle*
@@ -1406,7 +1402,8 @@ test_find_closest_point_to_line (void)
int
main (int argc, char **argv)
{
- init_random_ness ();
+ grand = g_rand_new ();
+
test_area ();
test_intersect ();
test_equal ();
@@ -1428,6 +1425,8 @@ main (int argc, char **argv)
test_gravity_resize ();
test_find_closest_point_to_line ();
+ g_rand_free (grand);
+
printf ("All tests passed.\n");
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]