A.A
A.A

Reputation: 4101

Random DOUBLE PRECISION between

How can I get a random number between two DOUBLE PRECISION number?

The following generate number outside of range

CREATE OR REPLACE FUNCTION random_between(low DOUBLE PRECISION, high DOUBLE PRECISION)
    RETURNS DOUBLE PRECISION AS
$$
BEGIN
    RETURN random() * (high - low + 1) + low;
END;
$$ language 'plpgsql' STRICT;

Upvotes: 1

Views: 271

Answers (1)

S-Man
S-Man

Reputation: 23686

demo:db<>fiddle

Remove the + 1 from the range.

Upvotes: 1

Related Questions