jdechirico
Programmer
I have a program that takes data entered from a keyboard and uses it as a random seed value, is there anyway to generate a string of up to 80 characters that could be used in place of data entered from a keyboard?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
char RandomChar()
{
return (char)((rand() % 78) + 30);
}
int main()
{
char str[81];
int i;
srand(time());
for ( i = 0; i < 80; ++i )
{
str[i] = RandomChar();
}
str[80] = '\0';
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char *rand_str(char *dst, int size)
{
static const char text[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i, len = rand() % (size - 1);
for ( i = 0; i < len; ++i )
{
dst[i] = text[rand() % (sizeof text - 1)];
}
dst[i] = '\0';
return dst;
}
int main (void)
{
char mytext[10];
srand(time(0));
puts(rand_str(mytext, sizeof mytext));
puts(rand_str(mytext, sizeof mytext));
puts(rand_str(mytext, sizeof mytext));
return 0;
}
/* my output
fEKWZmOQ
IYF
NNabfD
*/