Re: [PATCH] small glib fix.



Hi,

> On Wednesday, May 30, 2001, at 03:35  PM, Damian Ivereigh wrote:
> 
> >> On Wednesday, May 30, 2001, at 02:21  PM, Anders Carlsson wrote:
> >>
> >>> Really? I just based it on the g_rand_boolean macro:
> >>>
> >>> #define g_rand_boolean(rand) (g_rand_int ((rand)) & (1<<15))
> >>>
> >>> Is that wrong too?
> >>
> >> On 30 May 2001 13:19:27 -0700, Darin Adler wrote:
> >> I think so.
> >
> > I don't think it makes much difference. If the g_rand_int() function
> > where truly random (i.e. each number had an equal chance of occuring,
> > regardless of what the last number was) then it would absolutely make
> > no difference (all your doing is selecting which bit to use). However
> > I would have thought that the least significant bit was more likely to
> > have a better spectral spread than the most significant bit.
> >
> > This is all dragging up college math that is a bit rusty.
> 
> My suggested version:
> 
> #define g_rand_boolean(rand) ((g_rand_int (rand) >> 15) & 1)
> 
> The g_rand_int() function is not "truly random". It's a pseudorandom
> number generator. But this is beside the point, because both the
> existing macro any my proposed changed macro use the 16th significant
> bit. Whether to use the most or least significant bit is not what I'm
> criticizing.
> 
> The issue is whether 0x8000 is a good value for a function that returns
> a "boolean" to return. the original function returns 0 half of the time
> and 0x8000 the other half of the time. I prefer to use 0 and 1 for
> boolean values.

Yes, you're right. After fixing the stupid bug in g_random_boolean I also made
both macros return 0 or 1.

Bye,
Sebastian
-- 
Sebastian Wilhelmi
mailto:wilhelmi ira uka de
http://goethe.ira.uka.de/~wilhelmi




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