moved rand's out of sql queries for pg