LINUX - 随机数

 

 

 

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <regex.h>

int main(){
    int iRandTmp=-1;
    int i = 0;
    iRandTmp = open("/dev/urandom", O_RDONLY);
    printf("first:%d\n\n\n\n\n\n",iRandTmp%65536);
    close(iRandTmp);

    int fd=0;
    char *buff=NULL;
    unsigned long ulTest = 0;
    int ulSeed;
    fd=open("/dev/urandom",O_RDONLY);
    read(fd,&ulSeed,sizeof(ulTest));
    printf("second:%u",ulTest%400);
    close(fd);
             
return 0;

}

 

posted @ 2019-09-04 09:47  chiwin  阅读(219)  评论(0编辑  收藏  举报