Number of ways to sample $x$ beads from 3 red beads, 3 green beads, and 3 blue beads Suppose I wanted to sample $x$ beads from 3 green, 3 blue, and 3 red beads (apart from colour, the beads are not distinct). I've been trying to find one equation I can use to solve for something like this (likely involving combinatorics), but I can't seem to figure it out. For $x=1$ the answer is just $3\choose1$. For $x=2$, if the beads are of different colours there are 3 ways, and if the beads are of the same colour there is also 3 choices to choose, so I get a total of 6. But I can't seem to find a pattern here to come up with one unified equation.

we will use generating functions Then , if the same color of beads are different from each other :
Generating function for different red beads = $$1 + C(3,1)x + C(3,2)x^2 + C(3,3)x^3 = 1+3x +3x^2 +x^3$$
Generating function for different blue beads = $$1 + C(3,1)x + C(3,2)x^2 + C(3,3)x^3 = 1+3x +3x^2 +x^3$$
Generating function for different green beads = $$1 + C(3,1)x + C(3,2)x^2 + C(3,3)x^3 = 1+3x +3x^2 +x^3$$
Then find the coefficient of $[x^k]$ in the expansion of $$(  1+3x +3x^2 +x^3)^3$$
If the same color beads are not distinct then :
Generating function for  red beads = $$ 1+x +x^2 +x^3$$
Generating function for  blue beads = $$ 1+x +x^2 +x^3$$
Generating function for  green beads = $$  1+x +x^2 +x^3$$
Then find the coefficient of $[x^k]$ in the expansion of $$(  1+x +x^2 +x^3)^3$$
