One of many ways int rand07() { int r; do { r = rand04() + 5 * rand04(); // 0 to 24. } while (r >= 8 * 3); return r / 3; }
On Sep 11, 10:07 pm, sourav <souravs...@gmail.com> wrote: > You are given a random no. generator function rand04() that generates > random numbers between 0 and 4 (i.e., 0,1,2,3,4) with equal > probability. You have to design a random no. generator function > rand07() that generates numbers between 0 to 7 (0,1,2,3,4,5,6,7) using > rand04() such that rand07() generates all numbers between 0 to 7 with > equal probability. > > How will you do that? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.