LoadRunner 脚本学习 -- 随机函数运用

直接上码

 

Action()
{
    int randnum;
    randnum = rand()%3+1;

    lr_output_message("随机得到的数是:%d", randnum);

    switch(randnum)
    {
    case 1:
    web_url("百度", 
        "URL=http://www.baidu.com/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTML", 
        LAST);
    break;

    case 2:
    web_url("有道", 
        "URL=http://www.youdao.com/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTML", 
        LAST);
    break;

    case 3:
    web_url("浩方", 
        "URL=http://www.cga.com.cn/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTML", 
        LAST);
    break;
    }
    return 0;
}

 

rand()%n : 随机数函数, rand()%3, 就是除3的余数,那么只可能是0-2。 然后+1,rand()%3+1,就是1-3中的随机数了。

 

posted @ 2014-03-13 09:27  KK&TT  阅读(357)  评论(0)    收藏  举报
AmazingCounters.com