rand(5) + (rand(5)%2);

On Tue, Jun 19, 2012 at 12:30 PM, Sourabh Singh <singhsourab...@gmail.com>wrote:

> @ sry
> condition should be:
>
> if(20*prob <= 500/7) :-)
>
>
> On Tue, Jun 19, 2012 at 12:26 AM, Sourabh Singh 
> <singhsourab...@gmail.com>wrote:
>
>> @ALL
>>
>> Given a random number generator say r(5) generates number between 1-5
>> uniformly at random , use it to in r(7) which should generate a random
>> number between 1-7 uniformly at random
>>
>> i have seen this on many site's but not a single correct solution. all
>> solution's posted got rejected by someone else.:
>> plz.. suggest some algo :
>>
>> my aprroach:
>>
>> let's assume a rectangle :
>>
>> 100      |___________________
>>             |___________________|______
>> 500/7   |                                      |            |
>>             |                                      |            |
>>             |___________________|______|
>>             0     1      2      3     4      5     6    7
>> now :
>>
>> let : num  = rand(5);
>>        prob = rand(5);
>>
>>        if(prob <= rand(5))
>>                         print  num
>>        else
>>                         print  5 + num*(2/5)
>>
>>
>>  --
>> 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.
>>
>
>  --
> 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.
>



-- 
Umer

-- 
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