RandBetweenI(Bottom: Variant; Top: Variant): Variant;
RandBetweenI(Bottom: object;
Top: object;
Context: Prognoz.Platform.Interop.Fore.ForeRuntimeContext): object;
Bottom. The least integer value returned by the RandBetweenI method.
Top. The greatest integer value returned by the RandBetweenI method.
Context. Context. The parameter is used only in Fore.NET.
The RandbetweenI method returns a random integer between two specified integers.
Use the IModelling.RandBetween method to get a random number between any two numbers.
Executing the example requires that the repository contains a modeling container with the MS identifier. This container includes a model with the MODEL_D identifier that is calculated by method of determinate equation and containing more than one input variable. The first and the second input variables must contain only integer values.
Add links to the Metabase, Ms system assemblies.
Sub UserRandBetweenI;
Var
Mb: IMetabase;
ModelSpace, ModelObj: IMetabaseObject;
Transf: IMsFormulaTransform;
Formula: IMsFormula;
Model: IMsModel;
Determ: IMsDeterministicTransform;
Term: IMsFormulaTerm;
Inp_1, Inp_2: String;
Expr: IExpression;
Begin
Mb := MetabaseClass.Active;
// Get the model
ModelSpace := Mb.ItemById("MS").Bind;
ModelObj := Mb.ItemByIdNamespace("MODEL_D", ModelSpace.Key).Edit;
Model := ModelObj As IMsModel;
Transf := Model.Transform;
Formula := Transf.FormulaItem(0);
Determ := Formula.Method As IMsDeterministicTransform;
// Get the first input variable
Term := Determ.Operands.Item(0);
Inp_1 := Term.TermToInnerText;
// Get the second input variable
Term := Determ.Operands.Item(1);
Inp_2 := Term.TermToInnerText;
// Set expression for calculation
Expr := Determ.Expression;
Expr.References := "Ms";
Expr.AsString := "RandBetweenI(" + Inp_1 + "," + Inp_2 + ")";
If Expr.Valid
Then ModelObj.Save;
Else Debug.WriteLine(Model is not saved: error in formula);
End If;
End Sub UserRandBetweenI;
After executing the example the model returns random numbers placed between appropriate points of the first and second input variables.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
ModelSpace, ModelObj: IMetabaseObject;
Transf: IMsFormulaTransform;
Formula: IMsFormula;
Model: IMsModel;
Determ: IMsDeterministicTransform;
Term: IMsFormulaTerm;
Inp_1, Inp_2: String;
Expr: IExpression;
Begin
Mb := Params.Metabase;
// Get the model
ModelSpace := Mb.ItemById["MS"].Bind();
ModelObj := Mb.ItemByIdNamespace["MODEL_D", ModelSpace.Key].Edit();
Model := ModelObj As IMsModel;
Transf := Model.Transform;
Formula := Transf.FormulaItem[0];
Determ := Formula.Method As IMsDeterministicTransform;
// Get the first input variable
Term := Determ.Operands.Item[0];
Inp_1 := Term.TermToInnerText();
// Get the second input variable
Term := Determ.Operands.Item[1];
Inp_2 := Term.TermToInnerText();
// Set expression for calculation
Expr := Determ.Expression;
Expr.References := "Ms";
Expr.AsString := "RandBetweenI(" + Inp_1 + "," + Inp_2 + ")";
If Expr.Valid
Then ModelObj.Save();
Else System.Diagnostics.Debug.WriteLine("Model is not saved: error in formulaquot;);
End If;
End Sub;
Expression 1:
RandBetweenI(Min({Brazil|BCA}),Max({Brazil|BCA}))
Result: the random number from the range: minimum value of the Brazil|BCA factor - maximum value of the Brazil|BCA factor. An error occurs if the factor contains real values.
Use: it can be used in formulas of calculated series of time series database and model formulas of modeling container that is a child of the time series database.
Expression 2:
RandBetweenI(Min(X1),0)
Result: the random number that is placed between minimum value of the X1 factor and zero.
Use: it can be used in model formulas of modeling container.
See also:
IModelling | Time Series Database: Calculator | Modeling Container: Editing Regressor or Formula