Thursday, 12 December 2013

Random function code

Here I am giving the random function code. This code is very useful in selection of random number out of a pool. Ex selection of 1 value from drop down, click on a link out of 10 link etc..

  web_reg_save_param("soc","LB=option value=\"","RB=\"","ORD=ALL",LAST);

TotalMatchesCount=atoi(lr_eval_string("{soc_count}"));

    if(TotalMatchesCount>0)
    {
        srand(time(NULL));
         random=rand()%TotalMatchesCount+1;
        
         sprintf(sRandomURL,"{soc_%d}",random);
        
         lr_save_string(lr_eval_string(sRandomURL),"soc_value");
         lr_output_message("Parameter value = %s",lr_eval_string(sRandomURL));

           lr_start_transaction("ABC");
           -------------
     Body=searchParamTxt=Search+Pol&gcDirectoryIn=First+name&pt1:r3:0:soc1={soc_value}
           -------------
          lr_end_transaction("ABC",LR_AUTO);
}
else
       
    {
        lr_output_message("%s","Not Found  link");
    }


Note: Suppose TotalMatchesCount is 5. Then random=rand()%TotalMatchesCount generates value between 0 to 4 so we add 1 so that it become 1 to 5. Now we can use soc_1..... soc_5.

 

No comments:

Post a Comment

How to Change Password of IUSR_METRO Account

Sometime we need to change the password of IUSR_METRO Account. This may be required due to compliance issue. Below are the steps to chang...