Thanks bricklen.
I found another way in PostgreSQL 9.1.0 Documentation.
SELECT * INTO random_number FROM random(); -- random function gives me a random value among 0.0 -- and 1.0
SELECT * INTO rounded_number FROM round(random_number * 5); -- this line is completly obviously.
Saludos, Karel Riverón
Consejo Científico Estudiantil
Universidad de las Ciencias Informáticas
Consejo Científico Estudiantil
Universidad de las Ciencias Informáticas
From: "bricklen" <bricklen@xxxxxxxxx>
To: "Karel Riveron Escobar" <kescobar@xxxxxxxxxxxxxxxxxx>
Cc: pgsql-general@xxxxxxxxxxxxxx
Sent: Saturday, May 25, 2013 11:50:03 AM
Subject: Re: [GENERAL] Random numbersOn Sat, May 25, 2013 at 8:45 AM, Karel Riveron Escobar <kescobar@xxxxxxxxxxxxxxxxxx> wrote:
I want to generate random numbers in Pl/pgSQL. How can I do this?To be more specific, I have to generate random numbers among 0 and 5.
One way:
select n from unnest(ARRAY[0,1,2,3,4,5]) n order by random() limit 1;