How to use /dev/random or urandom in C?

前端 未结 5 1982
面向向阳花
面向向阳花 2020-11-28 02:37

I want to use /dev/random or /dev/urandom in C. How can I do it? I don\'t know how can I handle them in C, if someone knows please tell me how. Tha

5条回答
  •  孤城傲影
    2020-11-28 03:04

    There are other accurate answers above. I needed to use a FILE* stream, though. Here's what I did...

    int byte_count = 64;
    char data[64];
    FILE *fp;
    fp = fopen("/dev/urandom", "r");
    fread(&data, 1, byte_count, fp);
    fclose(fp);
    

提交回复
热议问题