source: trunk/third/glib2/tests/rand-test.c @ 18159

Revision 18159, 1.3 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18158, which included commits to RCS files with non-trunk default branches.
Line 
1#undef G_DISABLE_ASSERT
2#undef G_LOG_DOMAIN
3
4#include <glib.h>
5
6const gint32 first_numbers[] =
7{
8  0x7a7a7a7a,
9  0xfdcc2d54,
10  0x3a279ceb,
11  0xc4d39c33,
12  0xf31895cd,
13  0x46ca0afc,
14  0x3f5484ff,
15  0x54bc9557,
16  0xed2c24b1,
17  0x84062503,
18  0x8f6404b3,
19  0x599a94b3,
20  0xe46d03d5,
21  0x310beb78,
22  0x7bee5d08,
23  0x760d09be,
24  0x59b6e163,
25  0xbf6d16ec,
26  0xcca5fb54,
27  0x5de7259b,
28  0x1696330c,
29};
30
31const gint length = sizeof (first_numbers) / sizeof (first_numbers[0]);
32
33int main()
34{
35  guint n;
36
37  GRand* rand = g_rand_new_with_seed (first_numbers[0]);
38
39  for (n = 1; n < length; n++)
40    g_assert (first_numbers[n] == g_rand_int (rand));
41
42  for (n = 1; n < 100000; n++)
43    {
44      gint32 i;
45      gdouble d;
46      gboolean b;
47
48      i = g_rand_int_range (rand, 8,16);
49      g_assert (i >= 8 && i < 16);
50     
51      i = g_random_int_range (8,16);
52      g_assert (i >= 8 && i < 16);
53
54      d = g_rand_double (rand);
55      g_assert (d >= 0 && d < 1);
56
57      d = g_random_double ();
58      g_assert (d >= 0 && d < 1);
59
60      d = g_rand_double_range (rand, -8, 32);
61      g_assert (d >= -8 && d < 32);
62 
63      d = g_random_double_range (-8, 32);
64      g_assert (d >= -8 && d < 32);
65 
66      b = g_random_boolean ();
67      g_assert (b == TRUE || b  == FALSE);
68 
69      b = g_rand_boolean (rand);
70      g_assert (b == TRUE || b  == FALSE);     
71    }
72
73  g_rand_free (rand);
74
75  return 0;
76}
77
Note: See TracBrowser for help on using the repository browser.