Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The rand48 family of functions provides another psuedopseudo-random alternative.

Code Block
bgColor#ccccff
long int li;
FILE* fd;

if(!(fd = fopen("/dev/random", "r")) {
   /* Handle error condition */
}

if(fread(&li, sizeof(li), 1, fd) != sizeof(li)) {
   /* Handle error condition */
}

fclose(fd);

printf("Random number: %ld\n", li);

...

Code Block
bgColor#ccccff
#include<Wincrypt.h>

 
HCRYPTPROV hCryptProv;
union {
    BYTE bs[sizeof(long int)];
    long int li;
} rand_buf;

if(!CryptGenRandom(hCryptProv, sizeof(rand_buf), &rand_buf) {
    /* Handle error */
} else {
    printf("Random number: %ld\n", rand_buf.li);
}

...