Adding functions to Standard Library
This commit is contained in:
parent
808d4ca420
commit
4a21ff3d46
39 changed files with 1465 additions and 51 deletions
43
src/StandardLibrary/Functions/Random/RandomNormalSpread.cs
Normal file
43
src/StandardLibrary/Functions/Random/RandomNormalSpread.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using CSMic;
|
||||
using CSMic.StandardLibrary.Functions.Random;
|
||||
|
||||
namespace CSMic.StandardLibrary.Functions.Random
|
||||
{
|
||||
public class RandomNormalSpread : RandomBase, ICodedFunction
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "randns";
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<FunctionArgument> ExpectedArguments
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new FunctionArgument("lower", FunctionValue.NUMBER);
|
||||
yield return new FunctionArgument("upper", FunctionValue.NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
public FunctionValue Execute(params FunctionArgument[] args)
|
||||
{
|
||||
return base.Execute(args, (_args) =>
|
||||
{
|
||||
var inputLower = _args[0].Value;
|
||||
var inputUpper = _args[1].Value;
|
||||
decimal lower = Convert.ToDecimal(inputLower.Value);
|
||||
decimal upper = Convert.ToDecimal(inputUpper.Value);
|
||||
|
||||
if(upper <= lower)
|
||||
{
|
||||
return FunctionValue.ZERO;
|
||||
}
|
||||
|
||||
return new FunctionValue(FunctionValueType.Numeric, NextDecimalNormal() * (upper - lower));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue