Tuesday, October 1, 2013

Random String Generator with no consecutive duplicate characters

this function generates a random string of required length with no consecutive duplicate characters. This can be used for generating passwords (with no duplicate consecutive characters like zzztest)

random_Generator(char* paramname, int length) {
char buffer[32] = "";
int r,i;
char c;
srand((unsigned int)time(0));
for (i = 0; i < length; i++) {
r = rand() % 25 + 65;
c = (char)r;
buffer[i] = c;
if (buffer[i] == buffer[i-1])
{
r = rand() % 25 + 65;
c = (char)r;
buffer[i] = c;
}
}
lr_save_string(buffer, paramname);
return 0;
}

Action()
{
random_Generator( "Random_LastName",
10 );
    lr_output_message("LastName  = %s", lr_eval_string("{Random_LastName}"));
return 0;
}

No comments:

Post a Comment