Re: Random numbers - Mailing list pgsql-general

From Karel Riveron Escobar
Subject Re: Random numbers
Date
Msg-id b029097f-dcfd-4ef0-bdb0-8b573bee4aee@ucimail4.uci.cu
Whole thread Raw
In response to Re: Random numbers  (bricklen <bricklen@gmail.com>)
List pgsql-general
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




From: "bricklen" <bricklen@gmail.com>
To: "Karel Riveron Escobar" <kescobar@estudiantes.uci.cu>
Cc: pgsql-general@postgresql.org
Sent: Saturday, May 25, 2013 11:50:03 AM
Subject: Re: [GENERAL] Random numbers


On Sat, May 25, 2013 at 8:45 AM, Karel Riveron Escobar <kescobar@estudiantes.uci.cu> 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;




pgsql-general by date:

Previous
From: Ian Lawrence Barwick
Date:
Subject: Re: Random numbers
Next
From: Szymon Guz
Date:
Subject: Re: Random numbers