Created
January 2, 2017 19:41
-
-
Save paulhandy/b1f3edc0e07969a8a0600609408992cc to your computer and use it in GitHub Desktop.
Prints a random tryte string
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
#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