SolvedGenerate A Random String

Posts 13 of 3 · Page 1 of 1
Generate A Random String
Sup guys, feel like a noob asking this but i need a way to generate a random string in C++ for a project that will be totatly awesome but relies on this.

I was thinking of using like rand() and then assigning a number to each letter but that seemed excessive

So any suggestions would be awesome
I'd do something like:

Code:
char *generateString(int len)
{
    char *str = (char*)calloc(len + 1, sizeof(char));
    for (int i = 0; i < len; i++)
        str[i] = (char)(rand() % 0x5E + 0x21);
    return str;
}
Posts 13 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?