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

Re: [HACKERS] Re: random() function produces wrong range

From: Dave Smith <dave(at)candata(dot)com>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgreSQL(dot)org, pgsql-general(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: random() function produces wrong range
Date: 2000-08-01 20:40:33
Message-ID: 398735C1.3537CD7A@candata.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackers
Stephan Szabo wrote:
> 
> On Tue, 1 Aug 2000, Tom Lane wrote:
> 
> > Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> writes:
> > > Actually, on my machines, both man pages for rand() and random() say
> > > they return values between 0 and RAND_MAX (whether that's true or not
> > > is another matter).  In my case RAND_MAX==INT_MAX so the change wouldn't
> > > be a problem, but it might be problematic on some of the 64 bit machines.
> >
> > Oh, that's interesting.  What platform do you use?  If RAND_MAX applies
> > to random() on some machines that'd probably explain why the code is
> > written like it is.  But on my box (HPUX) the rand() function is old
> > and crufty and considerably different from random().
> 
> That's from a pair of linux boxes, although checking on a FreeBSD box a
> friend has, his boxes man pages show the range as explicitly 0 to 2^31-1
> as your box does.

On my SCO 5.0.4 box, rand() from the man page...

The rand function uses a multiplicative congruential random-number
generator
  with period 2^32 that returns successive pseudo-random numbers in the
range
  from 0 to (2^15)-1.


The following functions define the semantics of the functions rand and
srand.

     static unsigned long int next = 1;
     int rand()
     {
          next = next * 1103515245 + 12345;
          return ((unsigned int)(next/65536) % 32768);
     }
     void srand(seed)
     unsigned int seed;
     {
          next = seed;
     }

 
-- 
Dave Smith
Candata Systems Ltd.
(416) 493-9020
dave(at)candata(dot)com

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2000-08-01 21:23:53
Subject: Re: Anyone care about type "filename" ?
Previous:From: The Hermit HackerDate: 2000-08-01 20:27:57
Subject: Re: Anyone care about type "filename" ?

pgsql-general by date

Next:From: Joel BurtonDate: 2000-08-01 21:07:49
Subject: RE: Postgres connect with Access
Previous:From: Stephan SzaboDate: 2000-08-01 20:20:44
Subject: Re: random() function produces wrong range

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group