On 25 May 2013 18:14, Karel Riveron Escobar <kescobar@xxxxxxxxxxxxxxxxxx> wrote:
How would be if I would want to generate values among 3 and 5?
Hi Karel,
try something like:
SELECT floor(3 + random()*(5-3+1))::INT
Or generally:
CREATE OR REPLACE FUNCTION random_range(INTEGER, INTEGER) RETURNS INTEGER AS $$ SELECT floor(($1 + ($2 - $1 + 1) * random()))::INTEGER; $$ LANGUAGE SQL;
and then:
SELECT random_range(3,5);
regards
Szymon