I wrote the source code for printing random numbers within a given limit. But it also returns some negative numbers, is that normal? If not, how to fix it?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main( int argc, char* argv[])
{
int fd, n;
fd = open("/dev/urandom", O_RDONLY);
if(fd == -1)
printf("ERROR: Cannot Open %s\n",argv[1]);
read(fd, &n, sizeof(n));
printf("%d\n",1+n%6);
close(fd);
}
source
share