For your problem, just select a random item from this list evenly:
[1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5]
In general, check this answer: Weighted random numbers
In TR1 and C ++ 0x, there is a <random> header that contains a discrete_distribution class for creating such numbers, among others.
You can also check the GSL, which contains much more random distributions (and random number generators) than the standard <random> library, (But keep in mind that GSL uses GPLv3.)
kennytm
source share