Skip to content

Instantly share code, notes, and snippets.

@adaedra
Created September 24, 2013 17:02
Show Gist options
  • Save adaedra/6687833 to your computer and use it in GitHub Desktop.
Save adaedra/6687833 to your computer and use it in GitHub Desktop.
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#define PASSWORD_LENGTH 10
int main(void) {
char pwd[PASSWORD_LENGTH + 1];
srandom(time(NULL));
memset(pwd, 0, PASSWORD_LENGTH + 1);
for (int i = 0; i < PASSWORD_LENGTH; ++i) {
char c = 0;
do {
c = random() % SCHAR_MAX;
} while (!isprint(c) || isspace(c));
pwd[i] = c;
}
printf("%s\n", pwd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment