using System.Collections.Generic;
List<int> NumbersAllowed = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
if (string.IsNullOrWhiteSpace(UserInput))
UserInput = Autopilot(NumbersAllowed);
Console.WriteLine("Autopilot selected: " + UserInput);
Console.WriteLine("You entered: " + UserInput);
static string Autopilot(List<int> NumbersAllowed)
Random rand = new Random();
int numberOfNumbersUsed = rand.Next(2, 6);
List<string> operators = new List<string> { "+", "-", "*", "/" };
List<int> availableNumbers = new List<int>(NumbersAllowed);
List<string> num = new List<string>();
List<string> op = new List<string>();
for (int i = 0; i < numberOfNumbersUsed; i++)
int index = rand.Next(availableNumbers.Count);
num.Add(availableNumbers[index].ToString());
availableNumbers.RemoveAt(index);
for (int i = 0; i < numberOfNumbersUsed - 1; i++)
int index = rand.Next(operators.Count);
op.Add(operators[index]);
string expression = num[0];
for (int i = 0; i < op.Count; i++)
expression += " " + op[i] + " " + num[i + 1];