LoadRunner生成随机位数的字符串
1、新建生成随机数函数文件randString.h
//生成随机字符串 char *randString(slen) { int i,randid; char temp[100]=""; char character_set[52] = {'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','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'}; for(i=1;i<slen;i++){ randid = rand()%52; sprintf(temp,"%s%c",temp,character_set[randid]); } return(temp); }
2、在loadrunner新建脚本,导入随机数函数头文件randString.h
右键新脚本空白区域,选择add files to script,添加头文件:
3、编辑globals.h文件
添加脚本:#include "randString.h"
4、编写action脚本,调用生成随机位数字符串函数
Action(){ char a[100]=""; strcpy(a,lr_eval_string(randString(32))); lr_output_message("%s",a); return 0; }
5、执行结果
生成32位随机字符串