Можете посмотреть такой пример функции.
//функция возвращает список делителей числа
public static List<int> getDenaminators(int num)
{
List<int> result = new List<int>();
for (int i = 2; i < num - 1; i++)
{
if (num % i == 0)
result.Add(i);
}
return result;
}
public static string Func(int num, int count)
{
List<int> deliteli = getDenaminators(num);
Random rnd = new Random();
int key;
string numString = "", operString = "", resultString = "";
int nextVal = 0;
if (count == 0)
return num.ToString();
if (deliteli.Count > 0)
key = rnd.Next(1, 5);
else
key = rnd.Next(1, 4);
switch (key)
{
case 1:
{
nextVal = rnd.Next(1, num);
numString = (num - nextVal).ToString();
operString = "+";
} break;
case 2:
{
nextVal = rnd.Next(1, num);
numString = (num + nextVal).ToString();
operString = "-";
} break;
case 3:
{
nextVal = rnd.Next(1, 11);
numString = (num * nextVal).ToString();
operString = "/";
} break;
case 4:
{
nextVal = deliteli[rnd.Next(0, deliteli.Count)];
numString = (num / nextVal).ToString();
operString = "*";
} break;
}
if (count == 1)
resultString = String.Format("{0} {1} {2}", numString, operString, Func(nextVal, count - 1));
else
resultString = String.Format("{0} {1} ({2})", numString, operString, Func(nextVal, count - 1));
return resultString;
}
static void Main(string[] args)
{
Console.WriteLine(Func(1024, 6));
}