Answers for "how to generate a random hexadecimal value in c"

0

how to generate a random hexadecimal value in c

#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;
}
Posted by: Guest on January-13-2021

Code answers related to "how to generate a random hexadecimal value in c"

Browse Popular Code Answers by Language