4 * author: hackbard@hackdaworld.dyndns.org
16 static u32 *c_ptr,*b_ptr;
18 int rand_init(char *rf)
22 if((rand_fd=open("/dev/urandom",O_RDONLY))<0)
24 puts("cannot open /dev/urandom");
29 if((rand_fd=open(rf,O_RDONLY))<0)
31 printf("cannot open %s\n",rf);
35 if((b_ptr=(u32 *)(malloc(BUFSIZE*sizeof(u32))))==NULL)
37 puts("failed allocating random buffer");
54 if(c_ptr>=b_ptr+BUFSIZE)
56 if(read(rand_fd,b_ptr,BUFSIZE*sizeof(u32))<BUFSIZE*sizeof(u32))
58 /* -> assume random file, end reached */
59 puts("warning, will read random file from beginning ...");
60 lseek(rand_fd,0,SEEK_SET);
61 read(rand_fd,b_ptr,BUFSIZE*sizeof(u32));
66 return((u32)(*(c_ptr++)*(max*1.0/((long long unsigned int)URAND_MAX+1))));
69 u32 get_rand_lgp(u32 max,double a,double b)
71 return((u32)(1.0*max*(-1.0*b+sqrt(b*b+2*a*((b+a/2)*get_rand(URAND_MAX)/((long long unsigned int)URAND_MAX+1))))/a));