Even if rand() gives uniformly distributed numbers (which it does) that does not imply that you will get a flat histogram, nor should you expect it to, nor should you desire it to be so.
Even if rand() gives uniformly distributed numbers (which it does) that does not imply that you will get a flat histogram, nor should you expect it to, nor should you desire it to be so.
I think the only way to do that would be a rand() which guaranteed no repetition until all possibilities have occurred, which is not exactly random. When you roll a die, there is some chance of rolling 3 sixes in a row. If you rolled 100 times, I suppose the distribution would be reasonable uniform, but for this reason you cannot ask it to be perfect -- that's not random.
Going back to my earlier idea, you could put all numbers into an array, shuffle it using rand(0), and then pop them off one at time from this "random list"; when you reach the end, shuffle and start again. No matter how many times you do that, you will end up with a dead even number of repetitions for each value, but the order in which they occur will be random.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge