Re: Still wondering about random numbers...

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: Still wondering about random numbers...
Дата
Msg-id 00a401c11f55$81bf1770$48d210ac@jecw2k1
обсуждение исходный текст
Ответ на Still wondering about random numbers...  ("Dr. Evil" <drevil@sidereal.kz>)
Ответы Re: Still wondering about random numbers...  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: How can I know the disk space used by a table?
Следующее
От: Nicholas Piper
Дата:
Сообщение: Another seq scan instead of index question