summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberts Muktupāvels <alberts.muktupavels@gmail.com>2021-03-16 14:04:16 +0200
committerAlberts Muktupāvels <alberts.muktupavels@gmail.com>2021-03-16 14:04:16 +0200
commit811b671e52d07b8737ae8008bb2bf18ebdca6d15 (patch)
tree703cba35fd6cf2b19d9e9d07e8b0344e5c06be0d
parent35d7c78aedaf92c48bfaad1f45d666c6068413d2 (diff)
downloadmetacity-811b671e52d07b8737ae8008bb2bf18ebdca6d15.tar.gz
testboxes: use GRand to generate random numbers
Coverity CID: #1418268
-rw-r--r--src/core/testboxes.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/core/testboxes.c b/src/core/testboxes.c
index f4cd3a50..e59db39b 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;
}