Skip to content

Instantly share code, notes, and snippets.

@gtklocker
Created August 3, 2012 19:29
Show Gist options
  • Save gtklocker/3250695 to your computer and use it in GitHub Desktop.
Save gtklocker/3250695 to your computer and use it in GitHub Desktop.
Password Generator
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
int main( int argv, char *argc[] ) {
assert( argv > 1 );
const int N = atoi( argc[ 1 ] ); // Password length
char i, randChar;
srand( time( NULL ) ); // Initialize random seed
for ( i = 0; i < N; ++i ) {
randChar = rand() % 36;
if ( randChar < 10 ) {
printf( "%c", randChar + '0' ); // [0-9]
}
else {
printf( "%c", randChar - 10 + 'a' ); // [a-z]
}
}
printf( "\n" );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment