Hello, im still new to this so i will try to keep my question on topic and clear. My end goal for the program i am writing is to write out my array in a random order without repeating, i already can make it print it in normal and reverse but the random
has gotten me stuck, i think the random generator rand isnt being put into the variables. any help is appreaciated :D
here is the code.
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayProgram
{
class Program
{
static void Main(string[] args)
{
string[] Array = { "Betos", "Wendy's", "Arby", "McDonalds", "Tucanos", "Tepanyaki", "Dairy Queen", "Texas Roadhouse", "Iceberg" };
Console.WriteLine("Hello, Welcome to my favorite restaurant list");
Console.WriteLine("1) Order");
Console.WriteLine("2) Reversed Order");
Console.WriteLine("3) Random Order");
string input = Console.ReadLine();
bool repeat = true;
while (repeat)
{
switch (input)
{
case "1":
for (int i = 0; i < Array.Length; i++)
{
Console.WriteLine(Array[i]);
}
break;
case "2":
for (int i = Array.Length - 1; i >= 0; i--)
{
Console.WriteLine(Array[i]);
}
break;
case "3":
Random rand = new Random(8);
int l;
List<int> ArrayIndex = new List<int>(Array.Length);
for (int i = 0; i < Array.Length; i++)
{
do
{
l = rand.Next(Array.Length);
}
while (ArrayIndex.Contains(l));
{
ArrayIndex.Add(l);
}
}
for (int j = 0; j < Array.Length; j++)
{
System.Console.WriteLine("{0}", Array[ArrayIndex[j]]);
}
break;
default:
Console.WriteLine("Put in a 1, 2, or 3");
break;
}
Console.ReadLine();
}
}
}
}