Wednesday 6 December 2023

PeopleCode to Generate Alpha Numeric Random String

 

Function GenerateUniqueKey() Returns string

   Local string &characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

   Local string &key = "";

   Local number &length = 12; /* Adjust the desired length of the key */

   

   For &i = 1 To &length

         

      &randomCharacter = Substring(&characters, Int(Rand() * 62), 1);

      If (&i = 5 Or

            &i = 9) Then

         &key = &key | "-";

      End-If;

      

      &key = &key | &randomCharacter;

      

   End-For;

   

   Return &key;

End-Function;


No comments:

Post a Comment