Created
April 10, 2013 13:37
-
-
Save perillamint/5354695 to your computer and use it in GitHub Desktop.
Random string generator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Released under GNU GPL v3. | |
#include <stdio.h> | |
static const char alphanum[] = | |
"0123456789" | |
"!@#$%^&*" | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
"abcdefghijklmnopqrstuvwxyz"; | |
int stringLength = sizeof(alphanum) - 1; | |
FILE *fd_rand; | |
unsigned int hwrandom() | |
{ | |
int data; | |
char *d = (char*)&data; | |
int i; | |
for(i=0; i<4; i++) | |
{ | |
*d = fgetc(fd_rand); | |
d++; | |
} | |
return data; | |
} | |
char genRandom() | |
{ | |
return alphanum[hwrandom() % stringLength]; | |
} | |
int main() | |
{ | |
srand(time(0)); | |
fd_rand = fopen("/dev/urandom", "r"); | |
int i; | |
int loop = hwrandom()%15+1; | |
for(i=0; i<loop; i++) | |
printf("%c", genRandom()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment