How to create a string of alphanumeric values???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • symbee
    New Member
    • Sep 2006
    • 2

    How to create a string of alphanumeric values???

    Hi all,

    I want to create a string of alphanumeric values. Actually it is for security purpose. I am using C++ and I want the fuction for that...

    Can anybody help regarding this?? Plzzzzzzzzzzz

    Best Regards,
    Symbee
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Use srand and rand to get random values in the range 0 - 61 (62 values)

    Convert these to uppercase letters, lowercase letters and digits.

    Code:
    if (value < 26)
    {
        outputCharacter = 'A' + value;
    }
    ...
    Strcitly speaking this isn't portable but it will work if you computer uses the ASCII character set.

    Comment

    • symbee
      New Member
      • Sep 2006
      • 2

      #3
      Thanx for ur reply..

      I want string like this 4gh5js83gk6l0s. ..what is the exact code to do this??

      Plz help

      Regards,
      symbee

      Comment

      • D_C
        Contributor
        • Jun 2006
        • 293

        #4
        Code:
        for each character in the string
        {
           /*int*/ random = (10+26)*rand();
           if(random < 10)
             random += '0';
           else
             random += 'a';
           string += (char)random;
        }

        Comment

        Working...