Re: Glib rand() revisited: RAND_MAX?



Hi Derek ,

> > >         Should g_rand_int() (in CVS) have an equivalent of RAND_MAX
> > > #defined?  (it would just be the highest number a guint32 can hold)
> 
> > As everybody knows the highest number a guint32 can hold is 2^32-1 I
> > dont think, we should have yet another constant for that. Other
> > opinions?
> 
>         It's not so much that we don't know what 2^32-1 is, as much as
> consistency with the standard C library "rand()" function.
> 
>         On many platforms RAND_MAX is simply equal to 2^32-1
> anyway--it's just a matter of being more like existing conventions.

This convertion exists, because RAND_MAX is not 2^32-1 everywhere whereas the
maximum of g_rand_int is 2^32-1 everywhere.

We are defining G_MAXLONG and G_MAXULONG in glibconfig.h, but not G_MAXUINT64,
because that is always 1^64-1, why defining G_MAXUINT32

Another reason not to define this is, that people should be using
g_rand_int_range() and not tamper with own solutions, that most likely will
not yield a good distribution.

Bye,
Sebastian
-- 
Sebastian Wilhelmi                   |            här ovanför alla molnen
mailto:wilhelmi@ira.uka.de           |     är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi   |



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]