diff --git a/src/database/models/location.rs b/src/database/models/location.rs index fe9328f..c29045a 100644 --- a/src/database/models/location.rs +++ b/src/database/models/location.rs @@ -17,7 +17,14 @@ impl Location { ) -> Result { sqlx::query_as!( Location, - "SELECT id, map, has_entities FROM locations WHERE has_entities = $1 ORDER BY RANDOM() LIMIT 1", + " + SELECT id, map, has_entities FROM locations + WHERE has_entities = $1 + OFFSET ( + SELECT floor(random() * (SELECT count(id) FROM locations WHERE has_entities = $1))::int + ) + LIMIT 1 + ", has_entities ) .fetch_one(&db.pool)