hash算法

// automagic number generator
int AutoMagic()
  {
   int m,dE;
   string s;

   s=StringConcatenate(EA_Name,MagicKey,Symbol(),Period(),DoubleToStr(AccountNumber(),0),AccountCompany());

   m=djb2(s);
   if(m<0)
      m=-m;
   dE=MathPow(10.0,MathMod(m/7,4)+5);
   m=MathMod(m,dE)+(m-MathMod(m,dE))/dE;
   if(m>dE)
      m=MathMod(m,dE);

   return(m);
  }
// djb2 hash
int djb2(string key)
  {
   int i,h=5381,c;
   for(i=0; i<StringLen(key); i++)
     {
      c = StringGetChar(key, i);
      h = (h << 5) + h + c;
     }
   return(h);
  }
本博客所有文章如无特别注明均为原创。作者:天泓评测
分享到:更多

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)