Fix to stupid bug in g_random_boolean, also both functions now return 1 or
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Thu, 31 May 2001 08:12:35 +0000 (08:12 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Thu, 31 May 2001 08:12:35 +0000 (08:12 +0000)
2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
g_random_boolean, also both functions now return 1 or 0 instead of
1<<15 or 0.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/grand.h
grand.h
tests/rand-test.c

index 74e0a47..98ae6ec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 74e0a47..98ae6ec 100644 (file)
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 74e0a47..98ae6ec 100644 (file)
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 74e0a47..98ae6ec 100644 (file)
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 74e0a47..98ae6ec 100644 (file)
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 74e0a47..98ae6ec 100644 (file)
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 74e0a47..98ae6ec 100644 (file)
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 74e0a47..98ae6ec 100644 (file)
@@ -1,5 +1,11 @@
 2001-05-31  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * grand.h (g_random_boolean, g_rand_boolean): Fix to stupid bug in
+       g_random_boolean, also both functions now return 1 or 0 instead of
+       1<<15 or 0.
+
+       * tests/rand-test.c: Extended testcases.
+
        * configure.in: Remove G_HAVE_ISO_CXX_VARARGS and
        G_HAVE_ISO_C_VARARGS and define G_HAVE_ISO_VARARGS directly
        guarded by #if(n)def __cplusplus.
index 8cbeff6..5accc1a 100644 (file)
@@ -49,7 +49,7 @@ void    g_rand_free            (GRand      *rand);
 void    g_rand_set_seed        (GRand      *rand,
                                 guint32     seed);
 
-#define g_rand_boolean(rand) (g_rand_int ((rand)) & (1<<15))
+#define g_rand_boolean(rand) ((g_rand_int (rand) & (1 << 15)) != 0)
 
 guint32 g_rand_int             (GRand      *rand);
 gint32  g_rand_int_range       (GRand      *rand,
@@ -62,7 +62,7 @@ gdouble g_rand_double_range    (GRand      *rand,
 
 void    g_random_set_seed      (guint32     seed);
 
-#define g_random_boolean() (g_rand_boolean ((rand)))
+#define g_random_boolean() ((g_random_int () & (1 << 15)) != 0)
 
 guint32 g_random_int           (void);
 gint32  g_random_int_range     (gint32      begin,
diff --git a/grand.h b/grand.h
index 8cbeff6..5accc1a 100644 (file)
--- a/grand.h
+++ b/grand.h
@@ -49,7 +49,7 @@ void    g_rand_free            (GRand      *rand);
 void    g_rand_set_seed        (GRand      *rand,
                                 guint32     seed);
 
-#define g_rand_boolean(rand) (g_rand_int ((rand)) & (1<<15))
+#define g_rand_boolean(rand) ((g_rand_int (rand) & (1 << 15)) != 0)
 
 guint32 g_rand_int             (GRand      *rand);
 gint32  g_rand_int_range       (GRand      *rand,
@@ -62,7 +62,7 @@ gdouble g_rand_double_range    (GRand      *rand,
 
 void    g_random_set_seed      (guint32     seed);
 
-#define g_random_boolean() (g_rand_boolean ((rand)))
+#define g_random_boolean() ((g_random_int () & (1 << 15)) != 0)
 
 guint32 g_random_int           (void);
 gint32  g_random_int_range     (gint32      begin,
index cd89f0a..d13735c 100644 (file)
@@ -40,15 +40,31 @@ int main()
     {
       gint32 i;
       gdouble d;
+      gboolean b;
 
       i = g_rand_int_range (rand, 8,16);
       g_assert (i >= 8 && i < 16);
       
+      i = g_random_int_range (8,16);
+      g_assert (i >= 8 && i < 16);
+
       d = g_rand_double (rand);
       g_assert (d >= 0 && d < 1);
 
+      d = g_random_double ();
+      g_assert (d >= 0 && d < 1);
+
       d = g_rand_double_range (rand, -8, 32);
       g_assert (d >= -8 && d < 32);
+      d = g_random_double_range (-8, 32);
+      g_assert (d >= -8 && d < 32);
+      b = g_random_boolean ();
+      g_assert (b == TRUE || b  == FALSE);
+      b = g_rand_boolean (rand);
+      g_assert (b == TRUE || b  == FALSE);     
     }
 
   g_rand_free (rand);