Support Forums

Full Version: Generate Random Number + Characters.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
char *GenerateRandomLetters(unsigned int len)
{
    char            *nick;
    unsigned int    i;

    if (len == 0 || len > MAX_RANDOM_LETTERS)
        len = rand()%(MAX_RANDOM_LETTERS-3) + 3;

    nick = (char *) malloc (len + 1);

    for (i = 0; i <= len; i++)
        nick[i] = (rand()%26) + 97;

    nick[len] = 0;

    return nick;
}

Code:
char *GenerateNumber(int Len)
{
    char *nick;
    int i;
    nick = (char *) malloc (Len);
    nick[0] = '\0';
    srand(GetTickCount());
    for (i = 0; i < Len; i++) {
        sprintf(nick, "%s%d", nick, rand()%10);
    }
    nick[i] = '\0';
    return nick;
}

Maybe usefull for some applications.

Oui