@Ankur:
First of all sorry for the delay in response. I was away for a while
with no internet access.
Coming to your query,
EACH of the number between 1 and 7 (1,7 inclusive) should occur with
equal probability of 1/7

Quoting wikipedia ... 
http://en.wikipedia.org/wiki/Uniform_distribution_%28discrete%29
" ... If a random variable has any of n possible values k1, k2, ,kn
that are equally probable, then it has a discrete uniform
distribution. The probability of any outcome ki  is 1 / n. .. "

I cannot forget this problem coz I faced it in one of the 6 grueling
rounds of Adobe where every time I proposed a solution the interviewer
came up with an explanation that the probability is not 1/7 :(


_dufus


On Sep 8, 5:36 pm, ankur aggarwal <ankur.mast....@gmail.com> wrote:
> @dufus
>
> tell me 1 thing
> do we have to make algo so that the prob is 1/7 or do we have to make so
> that prob of generating number between 1 to 7 is same may be( 1/10) etc ???
>
> On Tue, Sep 8, 2009 at 11:42 AM, Dufus <rahul.dev.si...@gmail.com> wrote:
>
> > Hardest part of this problem is to prove that the generated number
> > INDEED follow uniform distribution :D
>
> > _dufus
>
> > On Sep 8, 6:57 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 )
> > >         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