RndPermutation(Value: Integer): Array;
RndPermutation(Value: integer): System.Array;
Value. Array length.
The RndPermutation method performs pseudorandom permutation of an array.
Value of the Value parameter must not be greater than 0.
To execute the example, add a link to the MathFin system assembly.
Sub UserProc;
Var
i, n, m: integer;
mathrnd, mathrnd1: array Of integer;
Begin
n := 8;
m := 3;
mathrnd := math.RndSample(n, m);
mathrnd1 := math.RndPermutation(n);
If mathrnd <> Null Then
Debug.WriteLine("Array sample");
For i := 0 To math.RndSample(n, m).Length - 1 Do
Debug.WriteLine(mathrnd[i]);
End For;
Else Debug.WriteLine(math.ErrorMsg);
End If;
Debug.WriteLine("Permutation of numbers in the array");
If mathrnd1 <> Null Then
For i := 0 To math.RndPermutation(n).Length - 1 Do
Debug.WriteLine(mathrnd1[i]);
End For;
Else Debug.WriteLine(math.ErrorMsg);
End If;
End Sub UserProc;
After executing the example the array that has the length of N numbers is built. The M of numbers is randomly selected from the obtained array. Numbers in the source array are randomly permuted. The obtained arrays are displayed in the console window.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.MathFin;
…
Public Shared Sub Main(Params: StartParams);
Var
i, n, m: integer;
mathrnd, mathrnd1: array;
rnd: Prognoz.Platform.Interop.MathFin.MathClass;
Begin
n := 8;
m := 3;
rnd := New Prognoz.Platform.Interop.MathFin.MathClass();
mathrnd := rnd.RndSample(n, m);
mathrnd1 := rnd.RndPermutation(n);
If mathrnd <> Null Then
System.Diagnostics.Debug.WriteLine("Array sample");
For i := 0 To rnd.RndSample(n, m).Length - 1 Do
System.Diagnostics.Debug.WriteLine(mathrnd[i]);
End For;
Else System.Diagnostics.Debug.WriteLine(rnd.ErrorMsg);
End If;
System.Diagnostics.Debug.WriteLine("Permutation of numbers in the array");
If mathrnd1 <> Null Then
For i := 0 To rnd.RndPermutation(n).Length - 1 Do
System.Diagnostics.Debug.WriteLine(mathrnd1[i]);
End For;
Else System.Diagnostics.Debug.WriteLine(rnd.ErrorMsg);
End If;
End Sub;
See also: