George
George

Reputation: 45

Random.Range and how to getRandom

enter image description here

These 9 balls are generated randomly according to the code below.

   for(int i=0;i<balls.Length; i++)
    {
        getBallsRandom = new Randomizer(balls[i].sprites);
        balls[i].setCurrentSpriteIndex(getBallsRandom.getRandom());
    }

All I want is that every time you generate 3 balls of each color. For example in the image below.

enter image description here

Upvotes: 2

Views: 141

Answers (1)

coincoin
coincoin

Reputation: 4685

Make a list of your balls list_balls = [Green, Green, Green, Red, Red, Red, Grey, Grey, Grey].

Here the idea in pseudocode:

for i=1 to 3: // for each tube
  for j=1 to 3: // 3 balls in each tube
    Pick a random ball from `list_balls`
    Remove the chosen ball from `list_balls`

I let you the pleasure to write that in C#

Upvotes: 2

Related Questions