// probability distribution. The mean time, in Seconds is given
// in 'mean_time'.
// This returns immediately if we are backtesting
// and does not sleep.
指数分布
void O_R_Sleep(double mean_time, double max_time)
{
if (IsTesting()) {
return; // return immediately if backtesting.
}
double p = (MathRand()+1) / 32768.0;
double t = -MathLog(p)*mean_time;
t = MathMin(t,max_time);
int ms = t*1000;
if (ms < 10) {
ms=10;
}
Sleep(ms);
}//End void O_R_Sleep(double mean_time, double max_time)

发表评论