4 * author: hackbard@hackdaworld.dyndns.org
18 static u32 *c_ptr,*b_ptr;
20 int rand_init(char *rf)
24 if((rand_fd=open("/dev/urandom",O_RDONLY))<0)
26 puts("cannot open /dev/urandom");
31 if((rand_fd=open(rf,O_RDONLY))<0)
33 printf("cannot open %s\n",rf);
37 if((b_ptr=(u32 *)(malloc(BUFSIZE*sizeof(u32))))==NULL)
39 puts("failed allocating random buffer");
56 if(c_ptr>=b_ptr+BUFSIZE)
59 printf("getting another %d bytes of random data ...",BUFSIZE);
61 if(read(rand_fd,b_ptr,BUFSIZE*sizeof(u32))<BUFSIZE*sizeof(u32))
63 /* -> assume random file, end reached */
64 puts("warning, will read random file from beginning ...");
65 lseek(rand_fd,0,SEEK_SET);
66 read(rand_fd,b_ptr,BUFSIZE*sizeof(u32));
74 return((u32)(*(c_ptr++)*(max*1.0/((long long unsigned int)URAND_MAX+1))));
77 u32 get_rand_lgp(u32 max,double a,double b)
79 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));
82 u32 get_rand_reject(u32 max_x,u32 max_y,u32 *graph)