#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdlib.h>
+#include <math.h>
#include "random.h"
{
if(c_ptr>=b_ptr+BUFSIZE)
{
+#ifdef MORE_PRINTF
+ printf("getting another %d bytes of random data ...\n",BUFSIZE);
+#endif
if(read(rand_fd,b_ptr,BUFSIZE*sizeof(u32))<BUFSIZE*sizeof(u32))
{
/* -> assume random file, end reached */
read(rand_fd,b_ptr,BUFSIZE*sizeof(u32));
}
c_ptr=b_ptr;
+#ifdef MORE_PRINTF
+ printf("got it!\n");
+#endif
}
-
+
return((u32)(*(c_ptr++)*(max*1.0/((long long unsigned int)URAND_MAX+1))));
}
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));
}
+u32 get_rand_reject(u32 max_x,u32 max_y,u32 *graph)
+{
+ u32 x,y;
+ unsigned char ok;
+
+ ok=0;
+ while(!ok)
+ {
+ x=get_rand(max_x);
+ y=get_rand(max_y);
+ if(y<=graph[x]) ok=1;
+ }
+
+ return x;
+}