I am looking for a more efficient way to solve this problem. Lets say I have 10 inspirational quotes and I would like 3 to be chosen at random to be displayed. example:
string0 = "be patient";
string1 = "show resourcefulness";
string2 = "show perseverance";
string3 = "be content";
string4 = "appreciate more";
string5 = "live free";
string6 = "be optimistic";
string7 = "work with joy";
string8 = "show enthusiasm";
string9 = "do your best";
Console.WriteLine("press Enter to see 3 quotes");
Console.ReadLine();
//my own way of doing it was to have 3 new strings for the spotlight.
//then assigning an int for each quote to signify if it was already chosen or not.
Random rnd = new Random();
string display1 = "";
string display2 = "";
string display3 = "";
int quote0 = 0;
//i wont list the other ints for this example
flag1:
int dice = rnd.Next(10);
if (dice == 0) //a quote is chosen
{
if (quote0 == 1) //it's a duplicate
{
goto flag1; //to roll another number
}
display1 = string0;
quote0 = 1;
}
//there will be an if statement for dice 1-9 which i wont repeat
//this is repeated in flag2 for display2, and flag3 for display3
Console.WriteLine(display1);
Console.WriteLine(display2);
Console.WriteLine(display3);
Console.ReadLine();