Skip to content

Instantly share code, notes, and snippets.

@paulhandy
Created January 2, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulhandy/b1f3edc0e07969a8a0600609408992cc to your computer and use it in GitHub Desktop.
Save paulhandy/b1f3edc0e07969a8a0600609408992cc to your computer and use it in GitHub Desktop.
Prints a random tryte string
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MYCHAR 'A'
#define TRYTELEN 2673
char *get_random_trytes (int length) {
int i = 0, j;
char *out = malloc(sizeof(char)*length);
while (i < length) {
j = rand() % 27;
out[i] = j == 26 ? '9' : MYCHAR + j ;
i++;
}
return out;
}
int main(int argc, char *argv[]) {
srand(time(NULL));
int intvar;
if(argc < 2 || sscanf (argv[1], "%i", &intvar)!=1)
{
intvar = TRYTELEN;
}
fprintf(stdout, "%s", get_random_trytes(intvar));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment