Created
March 29, 2012 08:09
-
-
Save kladd/2234816 to your computer and use it in GitHub Desktop.
Random string generator.
This file contains hidden or 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
| /** | |
| * tag.c | |
| * | |
| * Generates a pseudo-random string of lowercase | |
| * letters of length TAG_LEN. A specific seed | |
| * for rand can be passed as an argument. | |
| */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| #define TAG_LEN 3 | |
| int main(int argc, char *argv[]) { | |
| static const int a='a', z='z'; | |
| int iseed, i; | |
| if (argv[1]) iseed = atoi(argv[1]); | |
| if (!iseed) iseed = (unsigned int)time(NULL); | |
| srand(iseed); | |
| for(i=0; i<TAG_LEN; i++) printf("%c", rand() % (z-a+1)+a ); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment