导航

[原创]Winrunner自己写的随机生成j位字母的TSL.

Posted on 2007-06-28 22:00  madduck  阅读(304)  评论(1)    收藏  举报

#--------------在iMin到iMax范围内,随机取一个数----------------
public function getRandom(in iMin, in iMax, out aRand[])
{
 auto iRange, i;
 if (iMin < 0 || iMin > iMax || (iMin + iMax)==0)
  return -1;
 if (int(iMin) != iMin || int(iMax) != iMax)
  return -1;
 iRange=(iMax-iMin) + 1;
# srand(GetTickCount());
 for (i=0; i<iRange; i++)
  aRand[i] = int(rand()*iRange) + iMin;
 return 0;
}

#---------------随机取j个字母,0<j<27----------------------------
public function getLetter(in j,out Result)
{
auto i,aRnd[],RandNum,TempLetter;
static Letter[ ]= {"a","b","c", "d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
j=int(j);
 if (j<0 || j>26)
 {
 texit;
 return -1;
 }
 else
 {
  if (getRandom(0,25,aRnd)==E_OK)
  {
   for (i=0; i<j; i++)
   {
    RandNum = aRnd[i];#随机从0-25取一个数字
    TempLetter=Letter[RandNum];
    Result=Result&TempLetter;
    }
  }
  printf(Result);
  return 0;
 }
}

for (i=0;i<10;i++)
{
getLetter(7.9);
}