Skip to content

Instantly share code, notes, and snippets.

@kladd
Created March 29, 2012 08:09
Show Gist options
  • Save kladd/2234816 to your computer and use it in GitHub Desktop.
Save kladd/2234816 to your computer and use it in GitHub Desktop.
Random string generator.
/**
* 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