-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.

3

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, simple and works fine.
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]);

1 Comment

I just updated, that was for Collection.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.