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
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