I find myself in need of a simple, easy-to-implement generator for passwords and came up with the following routine. It seems adequate for my needs but I'm wondering what others think. In particular, I'm wondering if re-randomizing the array between password (not character) generation loops would add any increased randomness.
Thoughts, comments, criticisms and good vibes always welcome ...
/****************************************************************************
* *
* File : rndgen.c *
* *
* Purpose : Implement a random number generator *
* and print out the results of multiple runs. *
* *
* Method : Using current clock (number of seconds since 1/1/1900) as seed *
* randomize the initial array and print out the result of the *
* 'sort'. Next, generate 10 groups of 15 random strings each *
* and print them out. By examination the groups appear to be *
* reasonably random although further testing would confirm or *
* negate that finding.
* *
* History : Date Who Reason *
* 2010.04.12 tgb Created original program *
* *
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char carray[] = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(int argc, char *argv[])
{
int i, j, k, n;
time_t seed;
char tmp;
// First seed the random number generator
seed = time( NULL );
srand(seed);
// Now sort the carray[] to randomize it as much as possible
for (i=0; i<62; i++)
{
n = rand() % 62;
tmp = carray[n];
carray[n] = carray[i];
carray[i] = tmp;
}
for (i=0; i<62; i++)
{
printf("%c", carray[i]);
}
printf("\n\n");
for (k=0; k<10; k++)
{
for (j=0; j<15; j++)
{
for (i=0; i<10; i++)
{
printf("%c", carray[rand() % 62]);
}
printf("\n");
}
printf("\n==========\n\n");
}
return 0;
}
And the output from a single run:
/* Sample run output follows:
7ZCJPtca9BsqEFhzWp2o8yKjA1XObYk5LnDS06Ili4mT3gUGVfQvMNwrRexuHd
6VFl58xE2L
inP1SkLnKG
aQwXIUPraa
oootHo8qT8
EDD7V69OPN
G8qN6b2Zdd
2zYRTJQ42W
Xbrcy1qPeU
eZxWbcmVl8
42FluUKxm8
74nqUytZYk
lAexygBo4q
UawyCVj1K0
5067OBNa2r
OZJclTSjEb
==========
P5MpQIHzko
t7AiTC2Umt
XULkMH3V4K
dNNYhmIqpg
OsXpY1BI5l
33jCol3un7
1sQs4l1SYW
mtX4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mcuEf
pou2iddFGG
Lewk9urM9e
pH6TGuLcjm
==========
KCUdhaKnzV
9VDoIucopW
TKFZDaYQ0s
vgRmIyCPD6
wzaTx4bB8O
guJJE03n9f
2zmGkrIjw0
pQJVrJXN8c
N127fKM1tv
GRuawvS96X
RK1oscOGTe
Xwko68yQ1M
Tn0WNwsX1o
J43ivneqPK
uQlNw1iwAG
==========
XtizVJ20cU
p27Rq5BumP
dBIf6pBAWZ
3DUj77S4TE
0gTLeRYEJz
9bURHjP7Tk
9zCWRAqshT
qpeR3ETmE1
OsYmgfIOdr
xLZyJRar36
zn2PrBKcqE
8VP8FY5HOZ
1YYc9ruUHe
TeiuH0pZBQ
WXHOUhAxDG
==========
Press any key to continue...
*/