public static void Main()
Console.WriteLine("Hello World");
Eval( "Truncate(11 / 3)" );
Eval( "RANDOM(1000,2000)" );
Eval( "RANDOM(20000,40000)*(Truncate(FARM_COUNT / 10) + 1)");
private static void Eval( string str )
Expression e = new Expression(str, EvaluateOptions.IgnoreCase);
e.EvaluateFunction += NCalcExtensionFunctions;
e.Parameters["FARM_COUNT" ] = 43;
var result = e.Evaluate();
Console.WriteLine(str + " = " + result);
private static void NCalcExtensionFunctions(string name, FunctionArgs functionArgs)
if (functionArgs.Parameters.Length == 0)
functionArgs.Result = (float) new Random().NextDouble();
else if (functionArgs.Parameters.Length == 1)
var p0 = functionArgs.Parameters[0].Evaluate();
functionArgs.Result = new Random().Next(0, p0Int+1);
functionArgs.Result = (float)(new Random().NextDouble() * (float)p0);
var p0 = functionArgs.Parameters[0].Evaluate();
var p1 = functionArgs.Parameters[1].Evaluate();
if (p0 is int p0Int && p1 is int p1Int)
functionArgs.Result = new Random().Next(p0Int, p1Int+1);
functionArgs.Result = (float)((float)p0 + new Random().NextDouble() * ((float)p1 - (float)p0));