Skip to content

Instantly share code, notes, and snippets.

@eeeeeeeeeevan
Created March 10, 2025 06:11
Show Gist options
  • Save eeeeeeeeeevan/246b2a01e3ad46845e3f1482c31a45f5 to your computer and use it in GitHub Desktop.
Save eeeeeeeeeevan/246b2a01e3ad46845e3f1482c31a45f5 to your computer and use it in GitHub Desktop.
for somethjibng
#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