Re: Still wondering about random numbers...

From: "Joe Conway" <joseph(dot)conway(at)home(dot)com>
To: "Dr(dot) Evil" <drevil(at)sidereal(dot)kz>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Still wondering about random numbers...
Date: 2001-08-07 15:27:44
Message-ID: 00a401c11f55$81bf1770$48d210ac@jecw2k1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-patches

> I am running on OpenBSD and Linux, both of which have
> cryptographic-quality RNGs built in. When I call RANDOM() in PG, do I
> get the old C library random numbers, which are not very random, or do
> I get high-quality random numbers from the crypto-RNG that's built in?
> Any sugestions for getting high-quality random numbers?

Looking through the source, I find:

/*
* drandom - returns a random number
*/
Datum
drandom(PG_FUNCTION_ARGS)
{
float8 result;

/* result 0.0-1.0 */
result = ((double) random()) / ((double) MAX_RANDOM_VALUE);

PG_RETURN_FLOAT8(result);
}

Looks like plain old C library random numbers. If you want to use
/dev/random or /dev/urandom, best bet would be to write your own C function.
You should also check through the contrib stuff -- I don't recall seeing RNG
functions in there, but I'm constantly amazed at what is in contrib that I
didn't notice before ;-)

HTH,

Joe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nicholas Piper 2001-08-07 15:30:07 Another seq scan instead of index question
Previous Message Tom Lane 2001-08-07 14:51:15 Re: How can I know the disk space used by a table?

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2001-08-07 16:00:56 Re: Still wondering about random numbers...
Previous Message Serguei Mokhov 2001-08-07 13:07:13 Re: Re: libpq.pot -> ru.po : Russian - Cyrillic - KOI8-R