@dave * *On Tue, Sep 8, 2009 at 7:27 AM, Dave <dave_and_da...@juno.com> wrote:
> > Use the rejection technique, something like this: > > do > { > do > U1 = random_1_to_5(); > while( U1 == 5 ); > // At this point, U1 is a uniform integer in the range 1 to 4. > U2 = random_1_to_5(); > * if( U1 > 2 )//* plz explain this step.. > * U2 += 5;* // plz explain this step.. > } > while( U2 > 7 ); > // At this point, U2 is a uniform random integer in the range 1 to 7. > > It takes on average 45/14 1_to_5 random numbers to make a 1_to_7 > random number. > > D --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@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 -~----------~----~----~----~------~----~------~--~---