Re: win32 random number generator

Поиск
Список
Период
Сортировка
От Claudio Natoli
Тема Re: win32 random number generator
Дата
Msg-id C9A33A2803C7F3479A02A333328A17471D3EC2@ewell.memetrics.local
обсуждение исходный текст
Ответ на win32 random number generator  ("Merlin Moncure" <merlin.moncure@rcsonline.com>)
Список pgsql-hackers-win32
Hello all,

Tom Lane writes:
> "Merlin Moncure" <merlin.moncure@rcsonline.com> writes:
> > Looks like this in lrand48(void):
> > //return ((long) _rand48_seed[2] << 15) + ((long)
> _rand48_seed[1] > 1);
>
> > is supposed to be this:
> > return (long)((unsigned long) _rand48_seed[2] << 15) +
> ((unsigned long)
> > _rand48_seed[1] >> 1);
>
> Hmm, _rand48_seed is unsigned short, so casting to either long or
> unsigned long should zero-extend, and then it doesn't matter whether
> the shifts think it's signed or not.  In short, that shouldn't change
> the behavior unless your compiler is broken.

Yes, ISTM the unsigned long's are superfluous. The bug is that the first version has a typo, in that greater-than is
appliedto rand48_seed[1], when it means to do right-shift... which explains why we're seeing "just over" 16-bits of
precision. 

Cheers,
Claudio

В списке pgsql-hackers-win32 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: win32 random number generator
Следующее
От: "Merlin Moncure"
Дата:
Сообщение: profiling on win32