How to get a random single category name in get_posts()?

You can use wp_get_post_categories to get the categories from your posts. Then you can use array_rand to get one random category from that array.

Check out these links on how to use wp_get_post_categories and array_rand to suit your needs:

https://developer.wordpress.org/reference/functions/wp_get_post_categories/
https://www.php.net/manual/en/function.array-rand.php

tech