optimizations for finding random document