Re: Still wondering about random numbers... - Mailing list pgsql-general

From Joe Conway
Subject Re: Still wondering about random numbers...
Date
Msg-id 00a401c11f55$81bf1770$48d210ac@jecw2k1
Whole thread Raw
In response to Still wondering about random numbers...  ("Dr. Evil" <drevil@sidereal.kz>)
Responses Re: Still wondering about random numbers...
List pgsql-general
> 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







pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How can I know the disk space used by a table?
Next
From: Nicholas Piper
Date:
Subject: Another seq scan instead of index question