some random() clarification needed - Mailing list pgsql-general

From Marc Millas
Subject some random() clarification needed
Date
Msg-id CADX_1aa3BNFvW_ivrao1NJFWFdiYbhDxg9vUGUDZz-7YuRwvqQ@mail.gmail.com
Whole thread Raw
Responses Re: some random() clarification needed
List pgsql-general
Hi,

when, in psql, on a postgres 12.3, I write:
select ceiling(random()*2582);
it does provide the expected answer, ie. a number between 1 and 2582, inclusive.
allways.
when I decide to use this to get a random row within a table prenoms having 2 columns
a id serial, and a prenom varchar, with explicitly 2582 lines, no gaps,
I write:
select id, prenom from prenoms where id=ceiling(random()*2582);

expecting to get, allways, one line.
But its not the case.
around 15% of time I get 0 lines which is already quite strange to me.
but 10% of time, I get a random number of lines, until now up to 4.
even weirder (to me !)

so, can someone please clarify ?

thanks,
regards,


Marc MILLAS
Senior Architect
+33607850334

pgsql-general by date:

Previous
From: Toomas Kristin
Date:
Subject: Re: Both side privileges
Next
From: "David G. Johnston"
Date:
Subject: Re: some random() clarification needed