Change sprite of image

Hi,

Is there maybe a better way to optimize the Colorize function of my script.

using UnityEngine;
using UnityEngine.UI;

public class ListController : MonoBehaviour
{
    public int[] compare_values = new int[8];
    public Sprite[] color; // the size will be 4
    public Image[] planets; // The size will be 8

    void Start()
    {
        Randomize();
    }

    private void Randomize()
    {
        for(int i = 0; i < compare_values.Length; i++)
        {
            compare_values *= Random.Range(0,4);*

}
this.Invoke(Colorize, 1);
}

private void Colorize()
{
planets[0].sprite = colors[compare_values[0]];
planets[1].sprite = colors[compare_values[1]];
planets[2].sprite = colors[compare_values[2]];
planets[3].sprite = colors[compare_values[3]];
planets[4].sprite = colors[compare_values[4]];
planets[5].sprite = colors[compare_values[5]];
planets[6].sprite = colors[compare_values[6]];
planets[7].sprite = colors[compare_values[7]];
}
}
I’m trying to set the sprite value of each image to the same as value from the compare_values array. I don’t want to set each element of the planets manually.

You can use another for loop for the Colorize method/function body which would make your life a little easier. So it would look like so:

private void Colorize()
     {
         for(int i = 0; i < planets.Length; i++)
         {
              planets<em>.sprite = colors[compare_values*];*</em>

}
}