I have a few million integers between 0 and 64K. I'd like to split them up into N buckets, where each bucket contains about the same number of items from a contiguous range. So for example, if I only had a single datapoint with each possible value, and 64 buckets, ideally I'd end up with a bucket for 0-1024, one for 1025-2048, etc.
What is an algorithm for calculating the bucket ranges that most evenly distributes the number of items?