That is a good one, you would need an index of all of the existing IDs then perform some kind of function to pick one at random
Many SQL databases (not sure on MongoDB) support a random “order by” so you could logically use our custom queries: https://strapi.io/documentation/developer-docs/latest/concepts/queries.html#bookshelf
And do something like what is described in this article: MySQL Select Random Records