2 #include "../port/lib.h"
6 #include "../port/error.h"
30 return i != 1 && i != (1 - sizeof(rb.buf));
36 return rb.wp != rb.rp;
42 up->basepri = PriNormal;
43 up->priority = up->basepri;
48 if(++rb.randomcount <= 100000)
53 sleep(&rb.producer, rbnotfull, 0);
58 * produce random bits in a circular buffer
63 if(rb.randomcount == 0 || !rbnotfull(0))
66 rb.bits = (rb.bits<<2) ^ rb.randomcount;
87 /* Frequency close but not equal to HZ */
88 addclock0link(randomclock, MS2HZ+3);
89 rb.ep = rb.buf + sizeof(rb.buf);
90 rb.rp = rb.wp = rb.buf;
91 kproc("genrandom", genrandom, 0);
95 * consume random bytes from a circular buffer
98 randomread(void *xp, ulong n)
111 for(e = p + n; p < e; ){
114 wakeup(&rb.producer);
115 sleep(&rb.consumer, rbnotempty, 0);
121 * beating clocks will be predictable if
122 * they are synchronized. Use a cheap pseudo-
123 * random number generator to obscure any cycles.
125 x = rb.randn*1103515245 ^ *rb.rp;
136 wakeup(&rb.producer);