You wrote....
Provided that you have a well-behaved rand() . Most
implementations
aren't and a perfect sort might not be reachable :-)
When I first fell in love with probability and statistics (high school), the
first thing I would do on any new computer I came into contact with was run
a chi squared distribution program on it so I could find the bias of the
random number generator in the system. Then anytime I used the rand() or
RND() or whatever that system called it I would apply the correction to
ensure a better "random" distribution. I would love to find a copy of the
program I wrote to do it. I decided to make it interesting to watch too - it
painted an ascii pyramid on the screen and dropped "balls" from the top
center and randomly hit each "pin" on the way down much like a pachino
machine. You'd get your distribution at the bottom via a count on each final
chute!
Jay West