Generate Random Password in C

I need a function to generate a random alphanumeric password in C code. It needs to be between 6-8 characters and follow the following rules:

Reject if same char appears # time: 4 or more
Reject if same char appears consecutively: 3 or more

I have the following random password working for numbers (0-9). I need to update it to include characters (a-z). I also need to add the validation rules above. Can someone please help me. I have been trying for days to update it but get a lot of compile errors... Thanks..

Here's what is working for number (0-9):

Random_Password()
{

int ran_int_num;

time_t seconds;
time(&seconds);

srand ((unsigned int) seconds);

/* multiply by 975 to generate a larger number */
ran_int_num = rand() * 975;

/**************************************************/
/* Need to cast the integer to character, so use sprintf /
/
%u = unsigned decimal integer %d = signed decimal integer /
/
************************************************/

sprintf(randompw, "%u", ran_int_num);
strncpy(newpw, randompw, 8);

return(0);

}

Here's what I tried to change it to, in order to generate an alphanumeric:

GenerateRandomID()

{
char password_chars["1234567890abcdefghijklmnopqrstuvwxyz"];
int i;
int length;
char ticketid;
int random;

   for \(i = 0; i < length; i\+\+\) \{
           random = rand\(0, strlen\(password_chars\) - 1\);
           ticketid = password_chars[random];
   \}
   return ticketid;

}

Here is a simple algorithm:

#include <stdlib.h>
#include <time.h>

static int srand_called=0;

char *random_pw(char *dest)
{
    size_t len=0;
    char *p=dest;
    int three_in_a_row=0;
    int arr[128]={0x0};

	/* be sure to have called srand exactly one time */
	if(!srand_called)
	{
		srandom(time(NULL));
		srand_called=1;
	}
	*dest=0x0; /* int the destination string*/
	for(len=6 + rand()%3; len; len--, p++) /* gen characters */
	{
		char *q=dest;
		*p=(rand()%2)? rand()%26 + 97: rand()%10 + 48;
		p[1]=0x0;
		arr[*p]++;                         /* check values */
		if(arr[*p]==3)
		{
			for(q=dest; q[2]>0 && !three_in_a_row; q++)	
				if(*q==q[1] && q[1]==q[2])
			   		three_in_a_row=1;
		}
		if(three_in_a_row || arr[*p]> 3 )
			return random_pw(dest);        /* values do not pass try again */
	}
    return dest;
}

Jim, thank you so much. I've been busy on other hot projects, so won't be able to try in for a couple of days. Thanks again for the very quick response.