Forgive me first if i am wrong since i didn't read all the posting ...
Here is a way to sol the problem.

n1 = random_1_5() + 0;
n2 = random_1_5() + 5;
..
n7= random_1_5() + (7-1)*5;

now n1 ... n7  is in range [1 ... 35]
Image we divde the range [1.. 35] into 5 parts, such as [1...7] , [8...14]
...

then we generat n8 = random_1_5()
we use n8 to pick a part we divided above.
so we get a range [a...b] , then we can get a number ni inside the range,
return ni;


On Mon, Sep 7, 2009 at 11:56 PM, 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