Created
March 10, 2025 06:11
-
-
Save eeeeeeeeeevan/246b2a01e3ad46845e3f1482c31a45f5 to your computer and use it in GitHub Desktop.
for somethjibng
This file contains hidden or 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
#include <stdio.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <limits.h> | |
long hrng(long min, long max) { | |
int fd = open("/dev/urandom", O_RDONLY); | |
unsigned char randb; | |
if (read(fd, &randb, sizeof(randb)) != sizeof(randb)) { | |
perror("read"); | |
close(fd); | |
exit(1); | |
} | |
close(fd); | |
return min + (randb * (max - min + 1)) / (UCHAR_MAX + 1); | |
} | |
int main() { | |
printf("%ld\n", hrng(1, 100)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment