A password generator in C. This doesn't make completely random passwords, rather ones that are still random enough but slightly easier to remember. This generator creates passwords with length 8 where every other character is [AEIOUY013] and every other [BCDFGHJKLMNPQRSTVWXZ2456789]. I.e. every other is a "vowel" with 0, 1 and 3 considered vowels (O, I and E, you see) and every other is a consonant.
This generator uses a far better algorithm to generate random numbers than the standard rand() function.
Come to think of it, 4 should also be a vowel...
#password-generator #random #c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
static char vowels[] = "AEIOUY013";
static char consonants[] = "BCDFGHJKLMNPQRSTVWXZ2456789";
int my_rnd(long int maxval);
/*
* my_rnd
*
* Returns a better random value than the standard C rand()
* function.
*
* Copied from http://members.cox.net/srice1/random/crandom.html .
*/
int my_rnd(long int maxval)
{
int retval;
double r;
double x;
double r2;
double r3;
r = (double)rand();
r2 = (double)RAND_MAX+(double)(1);
r3 = r / r2;
x = (r*maxval);
retval = (int) x;
return retval;
}
int main(void)
{
int len = 8;
int i;
int pos;
char c;
time_t t1;
/* Initialise the random generator */
(void) time(&t1);
for(i=0;i<len;i++)
{
if(i%2==0)
{
pos = my_rnd(27);
c = consonants[pos];
}
else
{
pos = my_rnd(9);
c = vowels[pos];
}
printf("%s", c);
}
printf("\n\n");
return 0;
}