Strange behavior of the random() function

From: r(dot)zharkov(at)postgrespro(dot)ru
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Strange behavior of the random() function
Date: 2018-09-26 02:54:56
Message-ID: 00b2388c8e5a8d1dfb693d2b59b00722@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,
Can anybody explain me that strange behavior?

select random() as "rnd", random() as "rnd1", random() as "rnd2"
from generate_series( 1, 5 );
---
0.948556384071708 0.769186236895621 0.381390900816768
0.684488877654076 0.594888080842793 0.214444123208523
0.668408528901637 0.452859566546977 0.924952184315771

All of the values are different.

select random() as "rnd", random() as "rnd1", random() as "rnd2"
from generate_series( 1, 3 )
order by random();
---
0.166236794553697 0.166236794553697 0.166236794553697
0.629051928408444 0.629051928408444 0.629051928408444
0.698161978274584 0.698161978274584 0.698161978274584

All values in any row are the same.

select random() as "rnd", random() as "rnd1", random() as "rnd2"
from generate_series( 1, 3 )
order by random() || 'test';
---
0.569052047561854 0.531697370111942 0.338135569822043
0.880468992516398 0.172520748339593 0.0296505615115166
0.862012444529682 0.119546371512115 0.21626165881753

All of the values are different again.

Is it a bug?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2018-09-26 03:35:40 Re: Strange behavior of the random() function
Previous Message Christopher Browne 2018-09-25 23:11:46 Re: Weird procedure question