Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: win32 random number generator


  • From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
  • To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • Cc: <pgsql-hackers-win32(at)postgresql(dot)org>
  • Subject: Re: win32 random number generator
  • Date: Mon, 22 Aug 2005 16:59:13 -0400
  • Message-id: <6EE64EF3AB31D5448D0007DD34EEB3417DD171(at)Herge(dot)rcsinc(dot)local>

> "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com> writes:
> > The windows random number of generator (a port of lrand48 in
random.c)
> > seems a little weak.  It seems to only offer about 16 bits of
precision.
> > Maybe there is a bug in the implementation?
> 
> > esp=# select count(*)  from (select distinct random() from
> > generate_series(1,1000000)) q;
> >  count
> > -------
> >  65559
> > (1 row)
> 
> That's pretty awful, all right.  I get numbers like this on two
> different Unix machines:

I'll research a fix.  Here's a clearer picture of the problem:

select distinct (random()::numeric(10,8)) * 65536 from
generate_series(1,1000000);

esp=# select distinct (random() * 65536)::numeric(15,8) from
generate_series(1,1000000);
    numeric
----------------
     0.00003052
     1.00003052
     2.00003052
     3.00003052
     4.00003052
[...]

oops! :)

Merlin



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group