Large random numbers

To add comments, please log in or register
OrangeTrading
26
OrangeTrading  

How could one generate large random numbers, ranging between 0 and X where X can be up to 1.500.000?

The standard random numbers generators I found are going up to 32767, not higher. And I need higher.

JC
1647
JC  
OrangeTrading:

How could one generate large random numbers, ranging between 0 and X where X can be up to 1.500.000?

The standard random numbers generators I found are going up to 32767, not higher. And I need higher.

Among many other approaches, see https://www.mql5.com/en/forum/216865#comment_5866478

Mladen Rakic
160517
Mladen Rakic  
OrangeTrading:

How could one generate large random numbers, ranging between 0 and X where X can be up to 1.500.000?

The standard random numbers generators I found are going up to 32767, not higher. And I need higher.

For a simple way to generate pseudo-random numbers you can use this :

int m_w = 521288629;
int m_z = 362436069;

void   SetSeed(int z=0, int w=0) { if (z != 0) m_z = z; if (w != 0) m_w = w; }
double GetRand()
{
    m_z = 36969 * (m_z & 65535) + (m_z >> 16);
    m_w = 18000 * (m_w & 65535) + (m_w >> 16);
         return ((m_z << 16) + m_w + 1.0);
}

Make sure to call the SetSeed() from somewhere (from init is good) - something like this :

   SetSeed(TimeLocal(),TimeLocal()*TimeCurrent());
Icham Aidibe
11680
Icham Aidibe  
OrangeTrading:

How could one generate large random numbers, ranging between 0 and X where X can be up to 1.500.000?

The standard random numbers generators I found are going up to 32767, not higher. And I need higher.

Multiply it by 45,777764213995788445692312387463. 

Mladen Rakic
160517
Mladen Rakic  
Icham Aidibe:

Multiply it by 45,777764213995788445692312387463. 

That will still generate just 32767 pseudo-random numbers - not 1.500.000
To add comments, please log in or register