For RNG in range [a,b] first thing is that all numbers should be generated
with equal probability.
in your case you are considering mid in both the ranges so you can modify it
like [a,mid],[mid+1,b]

still I think this will work fine as far as the ranges get divided equally..

like consider the case
[3,5] so division will be [3,4],[5] still probabilities will not be equal.

so answer should be
make b-a calls to rand(0,1) and return a+sum of return values of all the
calls

On Wed, Jul 6, 2011 at 11:20 PM, Nitish Garg <nitishgarg1...@gmail.com>wrote:

> Describe an implementation of Random(a, b) that only make calls to
> Random(0, 1)?
> Well I am thinking this way:
>
>    - Divide the range (a,b) in to 2 parts like (a, mid) and (mid, b) where
>    mid = (a+b)/2
>    - Select one of the range using a call to Random(0, 1).
>    - Then continue dividing the new range and selecting a new based on a
>    call to Random(0, 1) until we have two elements left.
>    - From the two elements one can easily be selected by a call to
>    Random(a, b).
>
> Is this approach correct? Or something else can be done?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/kCRJ22w0_wMJ.
> 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?hl=en.
>



-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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?hl=en.

Reply via email to