https://docs.mql4.com/math/MathRand and why not use the search function believe me it's free!
farhang wrote >>
https://docs.mql4.com/math/MathRandand why not use the search function believe me it's free!
The MathRand function returns larger integers like 32767 and i have to then start using mod to reduce and reduce. not what i want.https://docs.mql4.com/math/MathRandand why not use the search function believe me it's free!
thks.
Use MathFloor(MathRand(TimeLocal())/3276)
Roger:
Use MathFloor(MathRand(TimeLocal())/3276)
MathRand() has no inputs; I guess u meant calling MathSrand(TimeLocal()) before calling MathRand(). Anyway, an alternative way (and arguably a more 'standard' way of using MathRand()):
MathSrand(TimeLocal()); int num = MathRand()%10 + 1; // random number between 1 to 10 (even distribution)
You can find an excellent explanation in the section about MathRand() and MathSrand() here -> Articles -> Features -> MQL4 Language for Newbies. Technical Indicators and Built-In Functions.
No! Never take the least significant bits of a random number, they are not very random. Always use the most significant bits.
int num = 1 + 10*MathRand()/32768; // 1-10Also note you must divide by one more than MathRand's max value (32767) to get the proper range.
WHRoeder:
No! Never take the least significant bits of a random number, they are not very random. Always use the most significant bits.
No! Never take the least significant bits of a random number, they are not very random. Always use the most significant bits.
Interesting! Please explain.
I was referring to "Never take the least significant bits of a random number, they are not
very random". I studied EE and not computer science, so I might have some theoretical gaps in my knowledge in this regard. Googling this hasn't brought any relevant results. I thought those sort of problems were relevant years ago, but not with modern pseudo-random number systems.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
How do you generate a random number within a range of 1 to 10?