It has been discussed many times on the four forum. A search for the word MathRand yields more than 15 pages of results
For example, these topics:
https://www.mql5.com/ru/forum/123337
https://www.mql5.com/ru/forum/111855
- www.mql5.com
Please tell me how MathRand() gets values.
Can we expect MathRand() to be evenly distributed within the stated range?
I checked it in php some time ago.
It seems to generate large number of random numbers, and then plot.
Or you can find number of equal numbers for rough estimation, for example.
Generate a couple hundred numbers and write them to a file, then graph them with at least Excel.
I have not been able to read all the links offered to read))
Looking at the number of posts and the composition of participants in the discussion, I made a conclusion:
- You can safely use MathRand()
- If you don't have enough "resolution" 0...32767, you may use MathRand()*MathRand() - the distribution will not become strongly "skewed" in one or another side
It is not difficult to perform a rough estimation.
int A[32768] ;
for (int i=0; i<100000000; i++)
A[MathRand()]++;
but why?
For my purposes, the developers' comment is enough
- www.mql5.com
I need to randomly shift weights in fuzzy logic algorithms
The main thing is not to have constant "blockages" in any one direction.
Thanks for the "wow", of course, but in my case it's unnecessary))
on the account of
"- if there is not enough "resolution" 0...32767, you can take MathRand()*MathRand(), - the distribution will not become very "skewed" to one side or another"
I was wrong ...
expectation will shift to the left from the middle of the range (I suspect that to 1/4 * 32768^2, but I'm not sure of anything)
Anyway, my statement was wrong
on the account of
"- if there is not enough "resolution" 0...32767, you can take MathRand()*MathRand(), - the distribution will not become very "skewed" to one side or another"
I was wrong ...
expectation will shift to the left from the middle of the range (I suspect that to 1/4 * 32768^2, but I'm not sure of anything)
in general, my statement was wrong
hmlo d-range [0, (2^rstep)-1]
long ranD(int rstep) { long div=1; long r=0; for(int i=1;i<=rstep;i++) { if(MathRand()+1>16383.5){if(i==1){r=1;}else{r+=div;}} div=div*2; } return(r); }
You can use int or double or ulong instead of long.
rstep [0, 2^rstep-1] - did not understand what this parameter is
Question:
The double variable needs to be changed randomly with an accuracy of, say, up to the 8th decimal place
MathRand()/32768 will give a step of 0.00003 - not enough.
How to get uniformly distributed on (0...1) random value with step 0.00000001 with MathRand() ?
rstep [0, 2^rstep-1] - did not understand what this parameter is
Question:
The double variable needs to be changed randomly with an accuracy of, say, up to the 8th decimal place
MathRand()/32768 will give a step of 0.00003 - not enough.
How do I get a random variable evenly distributed at (0...1) with a sampling rate of 0.00000001 using MathRand() ?
at rsign=1 (-1,1) at rsign=0 (0,1)
double ranD(int rsign,int rstep) { double div=2; double r=0; for(int i=1;i<=rstep;i++) { if(MathRand()+1>16383.5){r+=1/div;} div=div*2; } if(rsign==1) { r=2*r-1; } return(r); }
rstep is a degree
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Please tell me how MathRand() gets values.
Can we expect MathRand() to be evenly distributed within the stated range?