I have tried
sumpro := proc(i) local a, b; a := rand(1 .. 10)(); b := rand(1 .. 10)(); print("Sum of ", a, " and ", b, " is ", a + b); end proc;
CodeGeneration:-CSharp(sumpro);
Error, (in Printer:-Print) invalid input: Printer:-Function:-Get expects its 1st argument, fname, to be of type string, but received CodeGeneration:-Names:-Name("rand")
Looks like that CodeGeneration:-CSharp cannot translate Maple library function rand to C#
You could try LLMs. Note that i is not used in your code. You can remove it.
Chat CPT:
using System;
class Program
{
static void SumPro(int i)
{
// Generate random numbers between 1 and 10
Random random = new Random();
int a = random.Next(1, 11); // Upper bound is exclusive, so use 11 for 1 to 10
int b = random.Next(1, 11);
// Print the sum
Console.WriteLine($"Sum of {a} and {b} is {a + b}");
}
static void Main(string[] args)
{
SumPro(0); // Example usage with a dummy parameter
}
}
Gemini:
using System;
public class MapleToCSharp
{
public static void SumPro(int i)
{
Random rand = new Random(); // Create a Random object outside the loop for better randomness
int a = rand.Next(1, 11); // Generates random integers between 1 (inclusive) and 11 (exclusive), i.e., 1 to 10
int b = rand.Next(1, 11);
Console.WriteLine($"Sum of {a} and {b} is {a + b}"); // Use string interpolation for cleaner output
}
public static void Main(string[] args)
{
// Example usage (equivalent to calling sumpro(i) in Maple):
SumPro(0); // The 'i' parameter isn't actually used in the Maple code, so we can pass any value.
SumPro(1); // Call it again to show it generates different random numbers each time
}
}