51Testing软件测试论坛

标题: 求教各位大侠代码中取到的随机数有什么用 [打印本页]

作者: yanlijasmine    时间: 2009-3-19 18:13
标题: 求教各位大侠代码中取到的随机数有什么用
请教各位大侠,下面代码中的randnum=rand()%3+3;在这里有什么用,小女子知道rand()%3+3取得到的随机数是3到5,但是不是很清楚放在这段代码中有什么用。

int randnum,x,i;
        web_url("localhost",
                "URL=http://localhost/",
                "TargetFrame=",
                "Resource=0",
                "RecContentType=text/html",
                "Referer=",
                "Snapshot=t1.inf",
                "Mode=HTML",
                EXTRARES,
                "Url=/Comm_Images/home-bg-body.gif", ENDITEM,
                "Url=/Comm_Images/Logo-home.gif", ENDITEM,
                "Url=/Comm_Images/seahorse.gif", ENDITEM,
                "Url=/Comm_Images/bg-search.gif", ENDITEM,
                "Url=/Comm_Images/button-search.gif", ENDITEM,
                "Url=/Comm_Images/home-fish.gif", ENDITEM,
                "Url=/Comm_Images/dotten-line.gif", ENDITEM,
                "Url=/WebResource.axd?d=KfvnEgkqAkSl4HiG-EFY7w2&t=633439354840000000", ENDITEM,
                LAST);

        randnum=rand()%3+3;
    lr_output_message("%d",randnum);


        for(i=0;i<randnum;i++)
        {
                lr_save_string(lr_eval_string("{categoryid}"),"temp");
        web_url(lr_eval_string("{temp}"),
                "URL=http://localhost/Products.aspx?page=0&categoryId={temp}",
                "TargetFrame=",
                "Resource=0",
                "RecContentType=text/html",
                "Referer=http://192.168.0.200:8080/",
                "Snapshot=t2.inf",
                "Mode=HTML",
                EXTRARES,
                "Url=/Comm_Images/button-wishlist-grey.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/bg-body.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/button-checkout.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/bg-sign-in.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/Logo.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/button-cart-grey.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/vertigo-icon.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Prod_Images/Birds/icon-penguin.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/spacer.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Prod_Images/Birds/icon-pelican.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Prod_Images/Birds/icon-duck.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                "Url=/Prod_Images/Birds/icon-owl.gif", "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS", ENDITEM,
                LAST);

        web_url(lr_eval_string("{productid}"),
                "URL=http://localhost/Items.aspx?productId={productid}&categoryId={temp}",
                "TargetFrame=",
                "Resource=0",
                "RecContentType=text/html",
                "Referer=http://localhost/Products.aspx?page=0&categoryId=BIRDS",
                "Snapshot=t3.inf",
                "Mode=HTML",
                EXTRARES,
                "Url=/Prod_Images/Birds/item-owl-day.gif", "Referer=http://localhost/Items.aspx?productId=BD-04&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/button-cart.gif", "Referer=http://localhost/Items.aspx?productId=BD-04&categoryId=BIRDS", ENDITEM,
                "Url=/Prod_Images/Birds/item-owl-night.gif", "Referer=http://localhost/Items.aspx?productId=BD-04&categoryId=BIRDS", ENDITEM,
                "Url=/Comm_Images/button-wishlist.gif", "Referer=http://localhost/Items.aspx?productId=BD-04&categoryId=BIRDS", ENDITEM,
                LAST);
ps:云层老师的代码,当时培训的时候将到的,但是现在看起来就不太清楚什么意思了
作者: wangshaozheng    时间: 2009-3-19 20:50
随机执行3到5次操作吧!就是那个购物网站,随机任意点击3-5次,应该是的吧!




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2