Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate Random Number + Characters.
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Beginner Scripts Project Evolution 0 756 08-26-2010, 02:33 PM
Last Post: Project Evolution

Forum Jump:


Users browsing this thread: 1 Guest(s)