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 )
        U2 += 5;
}
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.

Dave


On Sep 7, 10:56 am, ankur aggarwal <ankur.mast....@gmail.com> wrote:
>   Given a random number generator that generates numbers in the range 1 to
> 5, how can u create a random number generator to generate numbers in the
> range 1 to 7. (remember that the generated random numbers should follow a
> uniform distribution in the corresponding range)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to