Another option is to generate a larger range of random numbers. For example, combining multiple calls to rand() in order to generate a 64-bit (ulong) number. The output % 5 then still has bias, but becomes reduced to infinitesimal proportions. Also provides an answer if you need a range of random numbers larger than 32768.
For the full geek effect, the following GetRandomNumber() will use Windows API calls if available, and only fall back to the above function if "Allow DLL imports" is turned off. Microsoft say that this is "far more random than the data generated by the typical random number generator such as the one shipped with your C compiler"; in other words, far more random than what MT4 will be using.
Thanks for sharing. Hope to have more geeky suggestions from you. ;)
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Time for my own geeky suggestion...
Another option is to generate a larger range of random numbers. For example, combining multiple calls to rand() in order to generate a 64-bit (ulong) number. The output % 5 then still has bias, but becomes reduced to infinitesimal proportions. Also provides an answer if you need a range of random numbers larger than 32768.
For the full geek effect, the following GetRandomNumber() will use Windows API calls if available, and only fall back to the above function if "Allow DLL imports" is turned off. Microsoft say that this is "far more random than the data generated by the typical random number generator such as the one shipped with your C compiler"; in other words, far more random than what MT4 will be using.