# Mostrar post aleatório?

**URL:** <https://meta.discourse.org/t/show-random-post/83665>\
**Category:** Product Support\
**Created:** [23 Março , 2018 16:28 UTC](https://meta.discourse.org/t/show-random-post/83665 "2018-03-23T16:28:39Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)\
**Post date:** [28 Março , 2018 15:48 UTC](https://meta.discourse.org/t/show-random-post/83665/17 "2018-03-28T15:48:48Z")

</div>

> [@\_vincent](#):
>
> performances of order by random() queries.

I think it would be less expensive to pick off the top card from a shuffled category deck than it would be from topics,

I don’t care much for the “BETWEEN”. It would be like me to forget to change the numbers if the categories changed. Maybe you want some of the things I’ve NOTted but I think this would be less fragile and it seems to work well

```plaintext
WITH public AS (SELECT id AS public_cat_ids
                FROM categories
                WHERE NOT read_restricted
                AND name NOT LIKE 'Uncategorized'
                ORDER BY random()
                LIMIT 5 )
SELECT * 
FROM topics, public
WHERE category_id IN (public.public_cat_ids)
AND visible
AND NOT closed
AND NOT archived
ORDER BY random()
LIMIT 5 

```

---

_[View the full topic](https://meta.discourse.org/t/show-random-post/83665)._
