A method of generating random uuid LoadRunner

Source: Internet
Author: User
Tags 04x


Define the method in globals.h:



char * lr_guid_gen (char * paramName) {// Generate GUID method

typedef struct _GUID {

unsigned long Data1;

unsigned short Data2;

unsigned short Data3;

unsigned char Data4 [8];

} GUID;

GUID m_guid;

char buf [50];

char pNameStr [50];

CoCreateGuid (& m_guid);

// define the output format

// sprintf (buf, "{% 08lX-% 04X-% 04X-% 02X% 02X-% 02X% 02X% 02X% 02X% 02X% 02X}", // uppercase

sprintf (buf, "{% 08lx-% 04x-% 04x-% 02x% 02x-% 02x% 02x% 02x% 02x% 02x% 02x}", // lower case

// sprintf (buf, "% 08lX% 04X% 04X% 02X% 02X% 02X% 02X% 02X% 02X% 02X% 02X", // lowercase

m_guid.Data1, m_guid.Data2, m_guid.Data3,

m_guid.Data4 [0], m_guid.Data4 [1], m_guid.Data4 [2], m_guid.Data4 [3],

m_guid.Data4 [4], m_guid.Data4 [5], m_guid.Data4 [6], m_guid.Data4 [7]);

lr_save_string (buf, paramName);

sprintf (pNameStr, "{% s}", paramName);

return lr_eval_string (pNameStr);

}








Call the method in action:


char * test;

lr_load_dll ("ole32.dll"); // reference windows to generate GUID API

test = lr_guid_gen ("GUID"); // Call the lr_guid_gen () method above

lr_save_string (test, "GUID");

lr_output_message (test);

lr_output_message ("xxxxxxxxxxxxx:% s", lr_eval_string ("{GUID}"));











Another method:


LUID refers to a locally unique identifier. Everyone is familiar with GUID / UUID. Different from the requirements of GUID / UUID to ensure global uniqueness, as long as LUID guarantees local uniqueness, it means that it is guaranteed to be unique during each operation of the system. Inspired by: LoadRunner generates unique numbers + LoadRunner implementation: Calculates the string Md5.
   The principle is very simple, first generate a unique string, and then calculate Md5. The following code is slightly processed based on Md5:
void Md5toLUID (char * inStr, char * outStr)
 {
     int i;
     strncpy (outStr, inStr, 8);
     strcat (outStr, "-");
     for (i = 9; i <13; i ++)
         outStr = inStr [i-1];
     strcat (outStr, "-");
     for (i = 14; i <18; i ++)
         outStr = inStr [i-2];
     strcat (outStr, "-");
     for (i = 19; i <23; i ++)
         outStr = inStr [i-3];
     strcat (outStr, "-");
     for (i = 24; i <37; i ++)
         outStr = inStr [i-4];
     strcat (outStr, "\ 0");
 }

Calling method:
void main ()
 {
     char uStr [33], lStr [37];
     int i;
     
     for (i = 0; i <10; i ++) {
         lr_save_int (i, "iValue");
         GetUniqueString (lr_eval_string ("{iValue}"), uStr);
         GetMd5FromString (uStr, uStr);
         Md5toLUID (uStr, lStr);
         lr_output_message (lStr);
     }
 }

Output:
main.c (18): b7f163a8-f89c-59e3-6705-a3823a358c0d
 main.c (18): 20fcb7ab-0879-9572-fb5b-5c9848b37930
 main.c (18): 869b718d-126c-eaeb-b099-b1ec15d3c9db
 main.c (18): fd12c050-0975-3641-1de9-3685431d4a01
 main.c (18): 604bbc51-e787-1955-d721-ee5032640629
 main.c (18): 4fffdc48-0c44-66c9-34d7-697e473d20da
 main.c (18): a5d0d30c-5053-03e8-6e1a-1f112ef49007
 main.c (18): 4babb152-de2f-1136-d4a6-8aa78a90f2c7
 main.c (18): 833f6f33-da3d-efeb-7ec8-95f5491bf1a1
 main.c (18): 89148aad-8040-e70c-b406-69d56f570293
    When testing, this LUID can be used as a GUID / UUID. Unless multiple Contorllers are used at the same time and the script group name is the same, and even then, the chance of getting duplicate values is very small!
 The function is to concatenate the "-" to the specified position. The most commonly used is string replacement: C language implementation: replace the specified character in the string. 





A method of generating random uuid LoadRunner


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.