I logged also random index and what was left in contents, and everything seems good. I also checked the draw method again with only three balls like Hat(blue=1,red=1,green=1,gray=1), and it works normally.

the random index in the range from 0 - 10 for 11 balls(blue=3,red=2,green=6)

Here are some logged out data:

random 6 random 9 random 0 random 3 left {‘blue’: 2, ‘red’: 1, ‘green’: 4} lack 1 blue, get {‘green’: 2, ‘blue’: 1, ‘red’: 1}

random 3 random 6 random 7 random 3 left {‘blue’: 3, ‘green’: 4} lack 2 blue, get {‘red’: 2, ‘green’: 2}

random 10 random 5 random 4 random 7 left {‘blue’: 3, ‘red’: 1, ‘green’: 3} lack 2 blue, get {‘green’: 3, ‘red’: 1}

random 8 random 9 random 3 random 1 left {‘blue’: 2, ‘red’: 1, ‘green’: 4} lack 1 blue, get {‘green’: 2, ‘red’: 1, ‘blue’: 1}

random 10 random 3 random 3 random 3 left {‘blue’: 3, ‘green’: 4} lack 2 blue, get {‘green’: 2, ‘red’: 2}

random 2 random 1 random 7 random 2 left {‘blue’: 1, ‘red’: 1, ‘green’: 5} succsee {‘blue’: 2, ‘green’: 1, ‘red’: 1}

random 9 random 8 random 7 random 1 left {‘blue’: 2, ‘red’: 2, ‘green’: 3} lack 1 blue, get {‘green’: 3, ‘blue’: 1}

random 4 random 9 random 0 random 6 left {‘blue’: 2, ‘red’: 1, ‘green’: 4} lack 1 blue, get {‘red’: 1, ‘green’: 2, ‘blue’: 1}

random 5 random 5 random 6 random 5 left {‘blue’: 3, ‘red’: 2, ‘green’: 2} lack 2 blue, get {‘green’: 4}