Skip to content

Instantly share code, notes, and snippets.

@paulhandy paulhandy/main.c
Created Jan 2, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.