This C program generates random hexadecimal bytes of arbitrary length. The idea is to genrate decimal number first and convert it to hexadecimal.
Here is the source code of the C program to generate random hexadecimal bytes. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int length;
char str[] = "0123456789ABCDEF";
/* Seed number for rand() */
srand((unsigned int) time(0) + getpid());
length = rand() % 15 + 8;
while(length--) {
putchar(str[rand() % 16]);
srand(rand());
}
printf("\n");
return EXIT_SUCCESS;
}
$ gcc hexadecimal.c -o hexadecimal $ ./hexadecimal DE38C3A25D
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Related Posts:
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Apply for Computer Science Internship
- Check Computer Science Books
- Practice BCA MCQs