거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Class CRandom - MetaTrader 5용 라이브러리

조회수:
4474
평가:
(32)
게시됨:
2019.06.16 06:20
업데이트됨:
2022.03.15 22:32
\MQL5\Scripts\Random\
pcg_demo.mq5 (5.96 KB) 조회
\MQL5\Include\
Random.mqh (25.26 KB) 조회
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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