Files
mql5-skills/skills/mql5/references/docs/34-standardlibrary/1337-standardlibrary-mathematics-stat-mathsubfunctions-statmathsample.md
T
2026-06-23 21:47:51 +08:00

130 lines
4.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# MathSample
Generates a random sample from the array elements.
Version for working with an array of real values:
```
bool  MathSample(
   const double&  array[],           // array of values
   const int      count,             // count
   double&        result[]           // array of results
   )
```
Version for working with an array of integer values:
```
bool  MathSample(
   const int&     array[],           // array of values
   const int      count,             // count
   int&           result[]           // array of results
   )
```
Version for working with an array of real values. It is possible to obtain a sample with replacement:
```
bool  MathSample(
   const double&  array[],           // array of values
   const int      count,             // count
   const bool     replace,           // flag
   double&        result[],          // array of results
   )
```
Version for working with an array of integer values. It is possible to obtain a sample with replacement:
```
bool  MathSample(
   const int&     array[],           // array of values
   const int      count,             // count
   const bool     replace,           // flag
   int&           result[]           // array of results
   )
```
Version for working with an array of real values, for which the probabilities of sampling are defined.
```
bool  MathSample(
   const double&  array[],           // array of values
   double&        probabilities[],   // array of probabilities
   const int      count,             // count
   double&        result[]           // array of results
   )
```
Version for working with an array of integer values, for which the probabilities of sampling are defined.
```
bool  MathSample(
   const int&     array[],           // array of values
   double&        probabilities[],   // array of probabilities
   const int      count,             // count
   int&           result[]           // array of results
   )
```
Version for working with an array of real values, for which the probabilities of sampling are defined. It is possible to obtain a sample with replacement:
```
bool  MathSample(
   const double&  array[],           // array of values
   double&        probabilities[],   // array of probabilities
   const int      count,             // count
   const bool     replace,           // flag
   double&        result[]           // array of results
   )
```
Version for working with an array of integer values, for which the probabilities of sampling are defined. It is possible to obtain a sample with replacement:
```
bool  MathSample(
   const int&     array[],           // array of values
   double&        probabilities[],   // array of probabilities
   const int      count,             // count
   const bool     replace,           // flag
   int&           result[]           // array of results
   )
```
Parameters
array[]
[in] Array of integer values.
probabilities[]
[in] Array of probabilities for sampling the elements.
count
[in] The number of elements.
replace
[in]  Parameter that allows sampling with replacement.
result[]
[out] Array to output the results.
Return Value
Returns true if successful, otherwise false.
Note
The replace=true argument allows performing random sampling of the elements with replacement back to the original sequence.