Re: win32 random number generator
"Claudio Natoli" <[email protected]> Tue, 23 Aug 2005 15:13:42 +1000
| Newsgroups | gmane.comp.db.postgresql.devel.win32 |
|---|---|
| Message-ID | <[email protected]> |
Hello all, Tom Lane writes: > "Merlin Moncure" <[email protected]> writes: > > Looks like this in lrand48(void): > > //return ((long) _rand48_seed[2] << 15) + ((long)=20 > _rand48_seed[1] > 1); >=20 > > is supposed to be this: > > return (long)((unsigned long) _rand48_seed[2] << 15) +=20 > ((unsigned long) > > _rand48_seed[1] >> 1); >=20 > 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 ve= rsion has a typo, in that greater-than is applied to rand48_seed[1], when i= t means to do right-shift... which explains why we're seeing "just over" 16= -bits of precision.=20 Cheers, Claudio ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster