If Not True Then False

PostgreSQL: Select a Random Number in a Range (Between Two Numbers) - Comment Page: 1

This is quick tip howto select a random number in a range. Example random number between 1-100 (>= 1 and < 100). This is actually very easy job with PostgreSQL own random() function, which returns random value between 0-1. Following example selects 5 random values using generate_series() function: SELECT random() FROM generate_series(1,5); random ------------------- ...
Tagged with:


Leave a Comment

Your email address will not be published. Required fields are marked *

Input your comment.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Input your name.

vipin raj

Nice one!
But why MAX is 999 while MIN is 100, that is the range is [100, 999)
You can make it inclusive [100, 1000] by using

select max(trunc((100 + random()* (700-99)))) from generate_series(1, 100000);

select max(trunc((start + random()* (end- (start – 1))))) from generate_series(1, 100000);

reply Reply