...
The rand48 family of functions provides another psuedopseudo-random alternative.
| Code Block | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
#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);
}
|
...