Last active
August 9, 2020 14:10
-
-
Save rfc-2549/ced4f409ed4628c204356904f673e7c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* random_number.c: | |
* Generates a fairly better random number than rand() | |
* This function grabs x bytes from /dev/urandom | |
* and converts it to a long long int. | |
*/ | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
unsigned long long int | |
random_number() | |
{ | |
int fd = open("/dev/random",O_RDONLY); | |
unsigned long long int buf; | |
read(fd,&buf,sizeof(buf)); /* Reads necessary bytes for an unsigned | |
long long int */ | |
return buf; | |
} | |
int | |
main(void) | |
{ | |
printf("%llu\n",random_number()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment