Missing API for getting just the count of a key range?

This reply in another topic is helpful Getting the number of key/value pairs it propose to manually build statistic but automate it a little bit. Also it seems like it also useful for doing a random key lookup.