Ticaret robotlarını ücretsiz olarak nasıl indirebileceğinizi izleyin
Bizi Twitter üzerinde bulun!
Fan sayfamıza katılın
Komut dosyasını ilginç mi buldunuz?
Öyleyse bir link gönderin -
başkalarının da faydalanmasını sağlayın
Komut dosyasını beğendiniz mi? MetaTrader 5 terminalinde deneyin
Kütüphaneler

Class CRandom - MetaTrader 5 için kütüphane

Görüntülemeler:
4475
Derecelendirme:
(32)
Yayınlandı:
2019.06.16 06:20
Güncellendi:
2022.03.15 22:32
\MQL5\Scripts\Random\ \MQL5\Include\
Bu koda dayalı bir robota veya göstergeye mi ihtiyacınız var? Freelance üzerinden sipariş edin Freelance'e git

MathRand() Function

The standard random number generator in MQL has a fairly limited number of possible values from 0 to 32767 (15-bits usable, 2^15 = 32,768 values).

It is classified as linear congruential generator (LCG) which is considered a very basic random number generator.

The implementation of MQL MathRand() can be found here: https://www.mql5.com/en/docs/predefined/_randomseed

This generator has easily detectable statistical flaws which fail most statistical tests of randomness from the PractRand test suite. 

For this reason, MathRand() is not suitable for large-scale Monte Carlo simulations or where high-quality randomness is critical. 


PCG Random Number Generator

PCG is a family of random number generators, which are fast, statistically excellent, and have small code size.

http://www.pcg-random.org

This class is a wrapper class around the high-quality 32-bits PCG generator. This RNG has an output range of 2^32 which means it can generate 4,294,967,296 possible values.

A permuted congruential generator (PCG) is a pseudorandom number generation algorithm developed in 2014 which applies an output transformation (random shift or rotation) to eliminate the short period problem in the low-order bits that other LCG generators suffer from. It achieves excellent statistical performance with small and fast code, and small state size.

The class provides an easy interface for random number generation.

//+------------------------------------------------------------------+
//| Class CRandom                                                    |
//| Usage: Random number generation using the 32-bit PCG generator.  |
//+------------------------------------------------------------------+
class CRandom
  {
public:
   //--- Constructor and destructor
                CRandom(void);                                       // Constructor (auto-seed)
                CRandom(const ulong initstate,const ulong initseq);  // Constructor (custom seed)
                                                                     
   //--- Methods for generation of random numbers                    
   int          RandomInteger(void);                                 // Random integer [0,2147483648)
   int          RandomInteger(const int max);                        // Random integer [0,max)
   int          RandomInteger(const int min,const int max);          // Random integer [min,max)
                                                                     
   double       RandomDouble(void);                                  // Random double  [0.0,1.0)
   double       RandomDouble(const double max);                      // Random double  [0.0,max)
   double       RandomDouble(const double min,const double max);     // Random double  [min,max)
                                                                     
   bool         RandomBoolean(void);                                 // Random true/false (equal probability)
   bool         RandomBoolean(const double prob_true);               // Random true/false (with prob_true)
                                                                     
   double       RandomNormal(void);                                  // Random double (normal distribution)
   double       RandomNormal(const double mu,const double sigma);    // Random double (normal distribution)
  };


This GRAPH was obtained for random double numbers from 0 to 10


And, that one for random integer numbers from 0 to 10


The BITMAP of the low-order bits shows also a random pattern



    GbpChf GbpChf

    Advisor for trading Gbp/Chf. Algorithm for bar opening prices. Timeframe H1.

    ArrowDrawingIndiEu ArrowDrawingIndiEu

    This indi will draw OBJ_ARROW_BUY/OBJ_ARROW_SELL when find signals on Arrow Indi Buffers.

    Smoothed CCI Smoothed CCI

    Smoothed CCI

    RSI candles - lite ressource RSI candles - lite ressource

    Improved version based on RSI_candles by © mladen 2018 https://www.mql5.com/en/code/20968