How to have numbers weigh more than others in probability?

So, I have an enemy, and I want to spawn that enemy in groups of 1, 2 or 3, but I want the groups of 1 to be the most common groups, and then groups of 2 a little more uncommon, and the groups of 3 to be the rarest. The final distribution would look something like this

I know how to do this for groups of maximum 3, but my maximum amount of enemies in a group is changable.

  • So what I am asking is: how can I do
    this for a variable amount of max
    enemies, for example the max number
    being 13, or 42 etc. I didn’t find
    any way to manipulate Random.Range so
    I get this output. Any ideeas?

I would make a larger array, fill it with all numbers that we shall chose from, but add some numbers multiple times, then find a random place in the larger array - some numbers will have different weight. It might be necessary to make the larger array length 100 to get a resolution of 1%.

int[] aSelectFrom = { 1, 1, 1, 2, 3 };

System.Random random = new System.Random();
int iSelection = random.Next(0, aSelectFrom.Length);
// 1 is 60%, 2 is 20%, 3 is 20%
int iValue = aSelectFrom[iSelection];