STANAANDREY

read from /dev/urandom

Nov 20th, 2025 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4.  
  5. #define SIZE 3
  6.  
  7. int main(void) {
  8.     FILE *fp = fopen("/dev/urandom", "rb");
  9.     if (fp == NULL) {
  10.         perror("fopen");
  11.         exit(EXIT_FAILURE);
  12.     }
  13.  
  14.     static uint64_t buff[SIZE];
  15.     size_t bytes = fread(buff, sizeof(*buff), SIZE, fp);
  16.     if (bytes != SIZE) {
  17.         fprintf(stderr, "Error reading from /dev/urandom\n");
  18.         exit(EXIT_FAILURE);
  19.     }
  20.  
  21.     for (size_t i = 0; i < bytes; i++) {
  22.         printf("%llu ", buff[i]);
  23.     }
  24.     putchar('\n');
  25.  
  26.     if (fclose(fp) == EOF) {
  27.         perror("fclose");
  28.     }
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment