Re: random() function produces wrong range
От | Christopher Masto |
---|---|
Тема | Re: random() function produces wrong range |
Дата | |
Msg-id | 20000804142828.B18784@netmonger.net обсуждение исходный текст |
Ответ на | Re: [GENERAL] Re: random() function produces wrong range (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Differences between int8 and int4 as pkeys and fkeys
|
Список | pgsql-hackers |
On Thu, Aug 03, 2000 at 11:45:39AM -0400, Tom Lane wrote: > Actually the odds are far better than that. If the range is 2^31-1 > then only about 2^-16th of the outputs should be less than 2^15. > So ten probes gives you a failure probability of about 2^-160 not > 2^-10. It occurs to me that Perl has to provide a portable rand function, so I looked at how its Configure script works. It's pretty much what you've been discussing. First it checks for a couple of possible random functions (preferring drand48(), then random(), then bitching and using rand()). int main() { register int i; register unsigned long tmp; register unsigned long max = 0L; for (i = 1000; i; i--) { tmp = (unsigned long) $randfunc(); if (tmp > max) max = tmp; } for (i = 0; max; i++) max /= 2; printf("%d\n",i); } Oh well. -- Christopher Masto Senior Network Monkey NetMonger Communications chris@netmonger.net info@netmonger.net http://www.netmonger.net Free yourself, free your machine, free the daemon -- http://www.freebsd.org/
В списке pgsql-hackers по дате отправления: