-1

How can I make a random color generator, but only using 5 colours that I choose for my program. Im doing a priority system that uses colors to attribute to each pacient at an hospital.

Thanks in advance.

Dany4k
  • 83
  • 2
  • 11

2 Answers2

5

Try this simple example:

static Color[] colors = { Color.Red, Color.Green... };
static Color GetRandomColor()
{
    var random = new Random();
    return colors[random.Next(colors.Length)];
}

And don't forget using System.Drawing.

Kfir Guy
  • 2,545
  • 2
  • 14
  • 22
1

Here you go

// Define your colors array
string[] colors = { '#4FC1E9' , '#FE424D', '#1AA6B7', '#967ADC', '#48cfad' };

// Get a random index
Random rnd = new Random();
int r = rnd.Next(colors.Length);

string randomColor = ((string)colors[r]);
Murhaf Sousli
  • 12,622
  • 20
  • 119
  • 185