Skip to content

Instantly share code, notes, and snippets.

@Dezinger
Created December 10, 2013 16:59
Show Gist options
  • Save Dezinger/7894050 to your computer and use it in GitHub Desktop.
Save Dezinger/7894050 to your computer and use it in GitHub Desktop.
Random Range
by Scott Bailey 'Artacus' 
http://wiki.postgresql.org/wiki/Random_Range
CREATE OR REPLACE FUNCTION random(numeric, numeric)
RETURNS numeric AS
$$
SELECT ($1 + ($2 - $1) * random())::numeric;
$$ LANGUAGE 'sql' VOLATILE;
SELECT random(1,10)::int, random(1,10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment