MQL code for random number generation

int random_int(MqlRates& rates[], double symbol_point,int range=2, bool use_tickcount=true)
{
     if(range > 0)
     {
        int len=ArraySize(rates);
        if(len > 0)
        {
           double bar_sum=0.0;
           for(int i=0;i < len;++i)
               bar_sum +=(rates[i].high - rates[i].low + MathAbs(rates[i].close - rates[i].open));
           // bar_sum has the same randomness as the market
           
           // make it integer convertable
           bar_sum /= symbol_point;
                      
           // add tickcount, to put random behaviour on backtest (where always the same rates selected)
           if(use_tickcount == true)
               bar_sum += GetTickCount();
               
           // scale random number to range
           int rnd=((int) bar_sum % range);
           
           //PrintFormat("rnd=%d bs=%.2f tc=%d dt=%s",rnd,bar_sum,GetTickCount(),TimeToStr(__rates_dyn[0].time));
           return rnd;
        }
     }
     return 0;
}