I look on some posts in SO about random queryset in Django. All i can find is that order_by('?')
is not fast and efficient at all, but my experience does not tell so.
I have a table with 30.000 entries (final production will have around 200.000 entries). I can create separate tables around 10-15k entries each.
So, i want to get very fast and efficient a random of 100 (maybe 200) items. Idea of creating list of 100 random numbers is in my opinion not good enough, because some PKs will be missing (because of deleting, etc..).
And, i don't want a generate a random number, and then 99 following items.
I will be using Postgresql (no special reason...i can choose other if they are better).
I tested order_by('id')[:100]
and it seems very fast (i think). It took only? 0.017s per list.
- Why the docs says that this is not good operation for random?
- Which random do you prefer?
- Is there any better way to do this?